Skip to content

Commit

Permalink
refactor: 移动 OnBeforeShowCallback 到 ContextMenu 组件上
Browse files Browse the repository at this point in the history
  • Loading branch information
ArgoZhang committed Aug 22, 2024
1 parent edd1750 commit 1b3de9c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 10 additions & 0 deletions src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public partial class ContextMenu
[Parameter]
public bool ShowShadow { get; set; } = true;

/// <summary>
/// 获得/设置 弹出前回调方法 默认 null
/// </summary>
[Parameter]
public Func<object?, Task>? OnBeforeShowCallback { get; set; }

private string ZoneId => ContextMenuZone.Id;

/// <summary>
Expand All @@ -55,6 +61,10 @@ protected override void OnInitialized()
internal async Task Show(MouseEventArgs args, object? contextItem)
{
ContextItem = contextItem;
if (OnBeforeShowCallback != null)
{
await OnBeforeShowCallback(contextItem);
}

Check warning on line 67 in src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor.cs

View check run for this annotation

Codecov / codecov/patch

src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor.cs#L65-L67

Added lines #L65 - L67 were not covered by tests
await InvokeVoidAsync("show", Id, args);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ public partial class ContextMenuZone
[Parameter]
public RenderFragment? ChildContent { get; set; }

/// <summary>
/// 获得/设置 弹出前回调方法 默认 null
/// </summary>
[Parameter]
public Func<object?, Task>? OnClickBefore { get; set; }

/// <summary>
/// 获得/设置 上下文菜单组件集合
/// </summary>
Expand All @@ -43,10 +37,6 @@ internal async Task OnContextMenu(MouseEventArgs args, object? contextItem)
// 弹出关联菜单
if (ContextMenu != null)
{
if (OnClickBefore is not null)
{
await OnClickBefore(contextItem);
}
await ContextMenu.Show(args, contextItem);
}
}
Expand Down

0 comments on commit 1b3de9c

Please sign in to comment.