diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index e8243e1f171..093db25ddde 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@  - 10.3.1-beta01 + 10.3.1-beta02 diff --git a/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor b/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor index 64d0b0843ae..feacbeda74f 100644 --- a/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor +++ b/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor @@ -1,4 +1,4 @@ -@namespace BootstrapBlazor.Components +@namespace BootstrapBlazor.Components @inherits BootstrapModuleComponentBase @attribute [BootstrapModuleAutoLoader] @@ -7,7 +7,7 @@ @ChildContent - @foreach (var context in _contextMenuItems) + @foreach (var context in _contextMenuItems.Where(i => i.IsShow)) { if (context is ContextMenuDivider) { diff --git a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuDivider.cs b/src/BootstrapBlazor/Components/ContextMenu/ContextMenuDivider.cs index 0aec3acb720..f543cff2726 100644 --- a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuDivider.cs +++ b/src/BootstrapBlazor/Components/ContextMenu/ContextMenuDivider.cs @@ -13,6 +13,13 @@ namespace BootstrapBlazor.Components; /// public class ContextMenuDivider : Divider, IContextMenuItem, IDisposable { + /// + /// + /// + /// 一般是通过业务逻辑判断是否显示 + [Parameter] + public bool IsShow { get; set; } = true; + [CascadingParameter] [NotNull] private ContextMenu? ContextMenu { get; set; } diff --git a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuItem.cs b/src/BootstrapBlazor/Components/ContextMenu/ContextMenuItem.cs index 98caf264315..6d144218041 100644 --- a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuItem.cs +++ b/src/BootstrapBlazor/Components/ContextMenu/ContextMenuItem.cs @@ -51,6 +51,13 @@ public class ContextMenuItem : ComponentBase, IContextMenuItem, IDisposable [Parameter] public Func? OnClick { get; set; } + /// + /// + /// + /// 一般是通过业务逻辑判断是否显示 + [Parameter] + public bool IsShow { get; set; } = true; + [CascadingParameter] [NotNull] private ContextMenu? ContextMenu { get; set; } diff --git a/src/BootstrapBlazor/Components/ContextMenu/IContextMenuItem.cs b/src/BootstrapBlazor/Components/ContextMenu/IContextMenuItem.cs index 8f1af1f40ea..f1c282bf726 100644 --- a/src/BootstrapBlazor/Components/ContextMenu/IContextMenuItem.cs +++ b/src/BootstrapBlazor/Components/ContextMenu/IContextMenuItem.cs @@ -11,5 +11,10 @@ namespace BootstrapBlazor.Components; /// public interface IContextMenuItem { - + /// + /// 获得/设置 是否显示,默认为 true 显示 + /// Gets or sets whether to display. Default is true + /// + /// 一般是通过业务逻辑判断是否显示 + bool IsShow { get; set; } } diff --git a/test/UnitTest/Components/ContextMenuTest.cs b/test/UnitTest/Components/ContextMenuTest.cs index 998195cdf4b..b91cd791c48 100644 --- a/test/UnitTest/Components/ContextMenuTest.cs +++ b/test/UnitTest/Components/ContextMenuTest.cs @@ -107,6 +107,36 @@ public async Task ContextMenu_Ok() Assert.True(clicked); } + [Theory] + [InlineData(true, true)] + [InlineData(false, false)] + public void IsShow_Ok(bool show, bool expected) + { + var cut = Context.Render(pb => + { + pb.AddChildContent(pb => + { + pb.AddChildContent(pb => + { + pb.Add(a => a.Icon, "fa fa-test"); + pb.Add(a => a.Text, "Test1"); + pb.Add(a => a.IsShow, show); + }); + pb.AddChildContent(pb => + { + pb.Add(a => a.IsShow, show); + }); + pb.AddChildContent(pb => + { + pb.Add(a => a.Icon, "fa fa-test"); + pb.Add(a => a.Text, "Test2"); + }); + }); + }); + var actual = cut.Markup.Contains("Test1"); + Assert.Equal(expected, actual); + } + [Fact] public async Task ContextMenu_TouchWithTimeout_Ok() {