Skip to content

Commit 66ec4ce

Browse files
AiYuZhenAiYuZhenArgoZhang
authored
feat(IContextMenuItem): add IsShow parameter (#7608)
* #7605 增加上下文菜单项反排序。 增加 TrimStartAndEndDivider 参数,确定开始及结尾菜单项不是分割线。 * 调整代码覆盖度。 * feat(ContextMenuItem): add IsShow parameter * Revert "调整代码覆盖度。" This reverts commit df336ea. * Revert "#7605" This reverts commit 538e7b8. * refactor: 更新 IsShow 逻辑 * test: 增加单元测试 * chore: bump version 10.3.1-beta02 --------- Co-authored-by: AiYuZhen <aizhen@aizhen.vip> Co-authored-by: Argo Zhang <argo@live.ca>
1 parent 856d896 commit 66ec4ce

6 files changed

Lines changed: 53 additions & 4 deletions

File tree

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>10.3.1-beta01</Version>
4+
<Version>10.3.1-beta02</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@namespace BootstrapBlazor.Components
1+
@namespace BootstrapBlazor.Components
22
@inherits BootstrapModuleComponentBase
33
@attribute [BootstrapModuleAutoLoader]
44

@@ -7,7 +7,7 @@
77
@ChildContent
88
</CascadingValue>
99
<RenderTemplate>
10-
@foreach (var context in _contextMenuItems)
10+
@foreach (var context in _contextMenuItems.Where(i => i.IsShow))
1111
{
1212
if (context is ContextMenuDivider)
1313
{

src/BootstrapBlazor/Components/ContextMenu/ContextMenuDivider.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ namespace BootstrapBlazor.Components;
1313
/// </summary>
1414
public class ContextMenuDivider : Divider, IContextMenuItem, IDisposable
1515
{
16+
/// <summary>
17+
/// <inheritdoc cref="IContextMenuItem.IsShow"/>
18+
/// </summary>
19+
/// <remarks>一般是通过业务逻辑判断是否显示</remarks>
20+
[Parameter]
21+
public bool IsShow { get; set; } = true;
22+
1623
[CascadingParameter]
1724
[NotNull]
1825
private ContextMenu? ContextMenu { get; set; }

src/BootstrapBlazor/Components/ContextMenu/ContextMenuItem.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ public class ContextMenuItem : ComponentBase, IContextMenuItem, IDisposable
5151
[Parameter]
5252
public Func<ContextMenuItem, object?, Task>? OnClick { get; set; }
5353

54+
/// <summary>
55+
/// <inheritdoc cref="IContextMenuItem.IsShow"/>
56+
/// </summary>
57+
/// <remarks>一般是通过业务逻辑判断是否显示</remarks>
58+
[Parameter]
59+
public bool IsShow { get; set; } = true;
60+
5461
[CascadingParameter]
5562
[NotNull]
5663
private ContextMenu? ContextMenu { get; set; }

src/BootstrapBlazor/Components/ContextMenu/IContextMenuItem.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,10 @@ namespace BootstrapBlazor.Components;
1111
/// </summary>
1212
public interface IContextMenuItem
1313
{
14-
14+
/// <summary>
15+
/// <para lang="zh">获得/设置 是否显示,默认为 true 显示</para>
16+
/// <para lang="en">Gets or sets whether to display. Default is true</para>
17+
/// </summary>
18+
/// <remarks>一般是通过业务逻辑判断是否显示</remarks>
19+
bool IsShow { get; set; }
1520
}

test/UnitTest/Components/ContextMenuTest.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,36 @@ public async Task ContextMenu_Ok()
107107
Assert.True(clicked);
108108
}
109109

110+
[Theory]
111+
[InlineData(true, true)]
112+
[InlineData(false, false)]
113+
public void IsShow_Ok(bool show, bool expected)
114+
{
115+
var cut = Context.Render<ContextMenuZone>(pb =>
116+
{
117+
pb.AddChildContent<ContextMenu>(pb =>
118+
{
119+
pb.AddChildContent<ContextMenuItem>(pb =>
120+
{
121+
pb.Add(a => a.Icon, "fa fa-test");
122+
pb.Add(a => a.Text, "Test1");
123+
pb.Add(a => a.IsShow, show);
124+
});
125+
pb.AddChildContent<ContextMenuDivider>(pb =>
126+
{
127+
pb.Add(a => a.IsShow, show);
128+
});
129+
pb.AddChildContent<ContextMenuItem>(pb =>
130+
{
131+
pb.Add(a => a.Icon, "fa fa-test");
132+
pb.Add(a => a.Text, "Test2");
133+
});
134+
});
135+
});
136+
var actual = cut.Markup.Contains("Test1");
137+
Assert.Equal(expected, actual);
138+
}
139+
110140
[Fact]
111141
public async Task ContextMenu_TouchWithTimeout_Ok()
112142
{

0 commit comments

Comments
 (0)