Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>10.3.1-beta01</Version>
<Version>10.3.1-beta02</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@namespace BootstrapBlazor.Components
@namespace BootstrapBlazor.Components
@inherits BootstrapModuleComponentBase
@attribute [BootstrapModuleAutoLoader]

Expand All @@ -7,7 +7,7 @@
@ChildContent
</CascadingValue>
<RenderTemplate>
@foreach (var context in _contextMenuItems)
@foreach (var context in _contextMenuItems.Where(i => i.IsShow))
{
if (context is ContextMenuDivider)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ namespace BootstrapBlazor.Components;
/// </summary>
public class ContextMenuDivider : Divider, IContextMenuItem, IDisposable
{
/// <summary>
/// <inheritdoc cref="IContextMenuItem.IsShow"/>
/// </summary>
/// <remarks>一般是通过业务逻辑判断是否显示</remarks>
[Parameter]
public bool IsShow { get; set; } = true;

[CascadingParameter]
[NotNull]
private ContextMenu? ContextMenu { get; set; }
Expand Down
7 changes: 7 additions & 0 deletions src/BootstrapBlazor/Components/ContextMenu/ContextMenuItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ public class ContextMenuItem : ComponentBase, IContextMenuItem, IDisposable
[Parameter]
public Func<ContextMenuItem, object?, Task>? OnClick { get; set; }

/// <summary>
/// <inheritdoc cref="IContextMenuItem.IsShow"/>
/// </summary>
/// <remarks>一般是通过业务逻辑判断是否显示</remarks>
[Parameter]
public bool IsShow { get; set; } = true;

[CascadingParameter]
[NotNull]
private ContextMenu? ContextMenu { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@ namespace BootstrapBlazor.Components;
/// </summary>
public interface IContextMenuItem
{

/// <summary>
/// <para lang="zh">获得/设置 是否显示,默认为 true 显示</para>
/// <para lang="en">Gets or sets whether to display. Default is true</para>
/// </summary>
/// <remarks>一般是通过业务逻辑判断是否显示</remarks>
bool IsShow { get; set; }
}
30 changes: 30 additions & 0 deletions test/UnitTest/Components/ContextMenuTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContextMenuZone>(pb =>
{
pb.AddChildContent<ContextMenu>(pb =>
{
pb.AddChildContent<ContextMenuItem>(pb =>
{
pb.Add(a => a.Icon, "fa fa-test");
pb.Add(a => a.Text, "Test1");
pb.Add(a => a.IsShow, show);
});
pb.AddChildContent<ContextMenuDivider>(pb =>
{
pb.Add(a => a.IsShow, show);
});
pb.AddChildContent<ContextMenuItem>(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()
{
Expand Down