From 00db538398c8f7f392e211c28f1945b4534b445c Mon Sep 17 00:00:00 2001
From: Argo Zhang
Date: Fri, 28 Mar 2025 12:00:24 +0800
Subject: [PATCH 01/16] =?UTF-8?q?refactor:=20=E7=A7=BB=E5=8A=A8=20Tab=20?=
=?UTF-8?q?=E5=8F=B3=E9=94=AE=E8=8F=9C=E5=8D=95=E9=80=BB=E8=BE=91=E5=88=B0?=
=?UTF-8?q?=E5=86=85=E9=83=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Components/Layout/Layout.razor | 29 +-----
.../Components/Layout/Layout.razor.cs | 6 +-
src/BootstrapBlazor/Components/Tab/Tab.razor | 34 ++++++-
.../Components/Tab/Tab.razor.cs | 92 +++++++++++++++++--
.../Components/Tab/Tab.razor.scss | 1 +
src/BootstrapBlazor/Locales/en.json | 14 +--
src/BootstrapBlazor/Locales/zh.json | 12 +--
7 files changed, 133 insertions(+), 55 deletions(-)
diff --git a/src/BootstrapBlazor/Components/Layout/Layout.razor b/src/BootstrapBlazor/Components/Layout/Layout.razor
index 4b5c4fe496a..67c3eda60cf 100644
--- a/src/BootstrapBlazor/Components/Layout/Layout.razor
+++ b/src/BootstrapBlazor/Components/Layout/Layout.razor
@@ -116,31 +116,7 @@
@
@if (UseTabSet)
{
- @if (ShowTabContextMenu)
- {
-
- @RenderTab
-
- @if (BeforeTabContextMenuTemplate != null)
- {
- @BeforeTabContextMenuTemplate(_tab)
- }
-
-
-
-
-
- @if (TabContextMenuTemplate != null)
- {
- @TabContextMenuTemplate(_tab)
- }
-
-
- }
- else
- {
- @RenderTab
- }
+ @RenderTab
}
else
{
@@ -153,6 +129,9 @@
ShowExtendButtons="ShowTabExtendButtons" ShowClose="ShowTabItemClose" AllowDrag="AllowDragTab"
DefaultUrl="@TabDefaultUrl" ExcludeUrls="@ExcludeUrls" IsOnlyRenderActiveTab="IsOnlyRenderActiveTab"
TabStyle="TabStyle" ShowToolbar="@ShowToolbar" ToolbarTemplate="@ToolbarTemplate"
+ ShowContextMenu="ShowTabContextMenu"
+ ContextMenuRefreshIcon="@TabContextMenuRefreshIcon" ContextMenuCloseIcon="@TabContextMenuCloseIcon"
+ ContextMenuCloseOtherIcon="@TabContextMenuCloseOtherIcon" ContextMenuCloseAllIcon="@TabContextMenuCloseAllIcon"
ShowRefreshToolbarButton="ShowRefreshToolbarButton" ShowFullscreenToolbarButton="ShowFullscreenToolbarButton"
RefreshToolbarButtonIcon="@RefreshToolbarButtonIcon" FullscreenToolbarButtonIcon="@FullscreenToolbarButtonIcon"
RefreshToolbarTooltipText="@RefreshToolbarTooltipText" FullscreenToolbarTooltipText="@FullscreenToolbarTooltipText"
diff --git a/src/BootstrapBlazor/Components/Layout/Layout.razor.cs b/src/BootstrapBlazor/Components/Layout/Layout.razor.cs
index 7937c288fc9..187fbea59b6 100644
--- a/src/BootstrapBlazor/Components/Layout/Layout.razor.cs
+++ b/src/BootstrapBlazor/Components/Layout/Layout.razor.cs
@@ -509,10 +509,6 @@ protected override void OnParametersSet()
TooltipText ??= Localizer[nameof(TooltipText)];
MenuBarIcon ??= IconTheme.GetIconByKey(ComponentIcons.LayoutMenuBarIcon);
- TabContextMenuRefreshIcon ??= IconTheme.GetIconByKey(ComponentIcons.TabContextMenuRefreshIcon);
- TabContextMenuCloseIcon ??= IconTheme.GetIconByKey(ComponentIcons.TabContextMenuCloseIcon);
- TabContextMenuCloseOtherIcon ??= IconTheme.GetIconByKey(ComponentIcons.TabContextMenuCloseOtherIcon);
- TabContextMenuCloseAllIcon ??= IconTheme.GetIconByKey(ComponentIcons.TabContextMenuCloseAllIcon);
}
///
@@ -627,7 +623,7 @@ public virtual Task HandlerException(Exception ex, RenderFragment err
private string? GetTargetString() => IsFixedTabHeader ? ".tabs-body" : null;
- private async Task OnRefrsh(ContextMenuItem item, object? context)
+ private async Task OnRefresh(ContextMenuItem item, object? context)
{
if (context is TabItem tabItem)
{
diff --git a/src/BootstrapBlazor/Components/Tab/Tab.razor b/src/BootstrapBlazor/Components/Tab/Tab.razor
index e1fafcdbe15..a3afbe07197 100644
--- a/src/BootstrapBlazor/Components/Tab/Tab.razor
+++ b/src/BootstrapBlazor/Components/Tab/Tab.razor
@@ -6,9 +6,35 @@
{
@Body
}
+else if (ShowContextMenu)
+{
+
+ @RenderTab
+
+ @if (BeforeContextMenuTemplate != null)
+ {
+ @BeforeContextMenuTemplate(this)
+ }
+
+
+
+
+
+ @if (ContextMenuTemplate != null)
+ {
+ @ContextMenuTemplate(this)
+ }
+
+
+}
else
{
-
+ @RenderTab
+}
+
+@code {
+ RenderFragment RenderTab =>
+ @
-}
-
-@code {
+
;
+
RenderFragment
RenderTabItem => item =>
@
@RenderTabItemContent(item)
diff --git a/src/BootstrapBlazor/Components/Tab/Tab.razor.cs b/src/BootstrapBlazor/Components/Tab/Tab.razor.cs
index 8e9443e82d8..fb38b933d1f 100644
--- a/src/BootstrapBlazor/Components/Tab/Tab.razor.cs
+++ b/src/BootstrapBlazor/Components/Tab/Tab.razor.cs
@@ -358,7 +358,49 @@ public partial class Tab : IHandlerException
///
[Parameter]
public string? CloseTabNavLinkTooltipText { get; set; }
+
+ ///
+ /// Gets or sets whether enable tab context menu. Default is false.
+ ///
+ [Parameter]
+ public bool ShowContextMenu { get; set; }
+
+ ///
+ /// Gets or sets the template of before context menu. Default is null.
+ ///
+ [Parameter]
+ public RenderFragment? BeforeContextMenuTemplate { get; set; }
+
+ ///
+ /// Gets or sets the template of context menu. Default is null.
+ ///
+ [Parameter]
+ public RenderFragment? ContextMenuTemplate { get; set; }
+
+ ///
+ /// Gets or sets the icon of tab item context menu refresh button. Default is null.
+ ///
+ [Parameter]
+ public string? ContextMenuRefreshIcon { get; set; }
+
+ ///
+ /// Gets or sets the icon of tab item context menu close button. Default is null.
+ ///
+ [Parameter]
+ public string? ContextMenuCloseIcon { get; set; }
+ ///
+ /// Gets or sets the icon of tab item context menu close other button. Default is null.
+ ///
+ [Parameter]
+ public string? ContextMenuCloseOtherIcon { get; set; }
+
+ ///
+ /// Gets or sets the icon of tab item context menu close all button. Default is null.
+ ///
+ [Parameter]
+ public string? ContextMenuCloseAllIcon { get; set; }
+
[CascadingParameter]
private Layout? Layout { get; set; }
@@ -384,10 +426,9 @@ public partial class Tab : IHandlerException
[Inject, NotNull]
private DialogService? DialogService { get; set; }
-
- [CascadingParameter]
- private ContextMenuZone? ContextMenuZone { get; set; }
-
+
+ private ContextMenuZone? _contextMenuZone;
+
private ConcurrentDictionary LazyTabCache { get; } = new();
private bool HandlerNavigation { get; set; }
@@ -400,7 +441,7 @@ public partial class Tab : IHandlerException
private readonly ConcurrentDictionary _cache = [];
- private bool IsPreventDefault => ContextMenuZone != null;
+ private bool IsPreventDefault => _contextMenuZone != null;
///
///
@@ -439,6 +480,11 @@ protected override void OnParametersSet()
CloseIcon ??= IconTheme.GetIconByKey(ComponentIcons.TabCloseIcon);
RefreshToolbarButtonIcon ??= IconTheme.GetIconByKey(ComponentIcons.TabRefreshButtonIcon);
+ ContextMenuRefreshIcon ??= IconTheme.GetIconByKey(ComponentIcons.TabContextMenuRefreshIcon);
+ ContextMenuCloseIcon ??= IconTheme.GetIconByKey(ComponentIcons.TabContextMenuCloseIcon);
+ ContextMenuCloseOtherIcon ??= IconTheme.GetIconByKey(ComponentIcons.TabContextMenuCloseOtherIcon);
+ ContextMenuCloseAllIcon ??= IconTheme.GetIconByKey(ComponentIcons.TabContextMenuCloseAllIcon);
+
if (AdditionalAssemblies is null)
{
var entryAssembly = Assembly.GetEntryAssembly();
@@ -989,6 +1035,38 @@ public async Task Refresh(TabItem item)
await OnToolbarRefreshCallback();
}
}
+
+ private async Task OnRefresh(ContextMenuItem item, object? context)
+ {
+ if (context is TabItem tabItem)
+ {
+ await Refresh(tabItem);
+ }
+ }
+
+ private async Task OnClose(ContextMenuItem item, object? context)
+ {
+ if (context is TabItem tabItem)
+ {
+ await RemoveTab(tabItem);
+ }
+ }
+
+ private Task OnCloseOther(ContextMenuItem item, object? context)
+ {
+ if (context is TabItem tabItem)
+ {
+ ActiveTab(tabItem);
+ }
+ CloseOtherTabs();
+ return Task.CompletedTask;
+ }
+
+ private Task OnCloseAll(ContextMenuItem item, object? context)
+ {
+ CloseAllTabs();
+ return Task.CompletedTask;
+ }
///
///
@@ -1006,9 +1084,9 @@ protected override async ValueTask DisposeAsync(bool disposing)
private async Task OnContextMenu(MouseEventArgs e, TabItem item)
{
- if (ContextMenuZone != null)
+ if (_contextMenuZone != null)
{
- await ContextMenuZone.OnContextMenu(e, item);
+ await _contextMenuZone.OnContextMenu(e, item);
}
}
}
diff --git a/src/BootstrapBlazor/Components/Tab/Tab.razor.scss b/src/BootstrapBlazor/Components/Tab/Tab.razor.scss
index 0de01177aad..8865bff1506 100644
--- a/src/BootstrapBlazor/Components/Tab/Tab.razor.scss
+++ b/src/BootstrapBlazor/Components/Tab/Tab.razor.scss
@@ -700,6 +700,7 @@
display: flex;
align-items: center;
border-radius: var(--bs-border-radius);
+ user-select: none;
&:not(.disabled):not(:disabled):hover {
background-color: var(--bb-tabs-item-hover-bg-color);
diff --git a/src/BootstrapBlazor/Locales/en.json b/src/BootstrapBlazor/Locales/en.json
index 67168d6fa7f..847e2e1a738 100644
--- a/src/BootstrapBlazor/Locales/en.json
+++ b/src/BootstrapBlazor/Locales/en.json
@@ -105,11 +105,7 @@
"TooltipText": "Go top"
},
"BootstrapBlazor.Components.Layout": {
- "TooltipText": "Click to Expand/Collapse sidebar",
- "ContextRefresh": "Refresh",
- "ContextClose": "Close",
- "ContextCloseOther": "Close Other Tabs",
- "ContextCloseAll": "Close All Tabs"
+ "TooltipText": "Click to Expand/Collapse sidebar"
},
"BootstrapBlazor.Components.Logout": {
"PrefixDisplayNameText": "Welcome",
@@ -119,7 +115,7 @@
"Text": "Logout"
},
"BootstrapBlazor.Components.Menu": {
- "InvalidOperationExceptionMessage": "Sidemenu component cannot be used independently. Please use Menu component to set IsVertical = true"
+ "InvalidOperationExceptionMessage": "SideMenu component cannot be used independently. Please use Menu component to set IsVertical = true"
},
"BootstrapBlazor.Components.ModalDialog": {
"CloseButtonText": "Close",
@@ -182,7 +178,11 @@
"FullscreenToolbarTooltipText": "Fullscreen",
"PrevTabNavLinkTooltipText": "Prev Tab",
"NextTabNavLinkTooltipText": "Next Tab",
- "CloseTabNavLinkTooltipText": "Close"
+ "CloseTabNavLinkTooltipText": "Close",
+ "ContextRefresh": "Refresh",
+ "ContextClose": "Close",
+ "ContextCloseOther": "Close Other Tabs",
+ "ContextCloseAll": "Close All Tabs"
},
"BootstrapBlazor.Components.MultiFilter": {
"MultiFilterSearchPlaceHolderText": "Please enter ...",
diff --git a/src/BootstrapBlazor/Locales/zh.json b/src/BootstrapBlazor/Locales/zh.json
index 6dceb50ef15..22af6c45ff4 100644
--- a/src/BootstrapBlazor/Locales/zh.json
+++ b/src/BootstrapBlazor/Locales/zh.json
@@ -105,11 +105,7 @@
"TooltipText": "返回顶端"
},
"BootstrapBlazor.Components.Layout": {
- "TooltipText": "点击展开收缩左侧菜单",
- "ContextRefresh": "刷新",
- "ContextClose": "关闭",
- "ContextCloseOther": "关闭其他",
- "ContextCloseAll": "关闭全部"
+ "TooltipText": "点击展开收缩左侧菜单"
},
"BootstrapBlazor.Components.Logout": {
"PrefixDisplayNameText": "欢迎",
@@ -182,7 +178,11 @@
"FullscreenToolbarTooltipText": "全屏",
"PrevTabNavLinkTooltipText": "上一个标签",
"NextTabNavLinkTooltipText": "下一个标签",
- "CloseTabNavLinkTooltipText": "关闭"
+ "CloseTabNavLinkTooltipText": "关闭",
+ "ContextRefresh": "刷新",
+ "ContextClose": "关闭",
+ "ContextCloseOther": "关闭其他",
+ "ContextCloseAll": "关闭全部"
},
"BootstrapBlazor.Components.MultiFilter": {
"MultiFilterSearchPlaceHolderText": "请输入 ...",
From 041ae5935569fe382cd5e80e020279bbfd4b7261 Mon Sep 17 00:00:00 2001
From: Argo Zhang
Date: Fri, 28 Mar 2025 12:00:45 +0800
Subject: [PATCH 02/16] =?UTF-8?q?doc:=20=E6=9B=B4=E6=96=B0=E7=A4=BA?=
=?UTF-8?q?=E4=BE=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Components/Samples/Tabs.razor | 47 ++++++---------
.../Components/Samples/Tabs.razor.cs | 60 +++----------------
2 files changed, 26 insertions(+), 81 deletions(-)
diff --git a/src/BootstrapBlazor.Server/Components/Samples/Tabs.razor b/src/BootstrapBlazor.Server/Components/Samples/Tabs.razor
index 6d8015f47d7..824638445f9 100644
--- a/src/BootstrapBlazor.Server/Components/Samples/Tabs.razor
+++ b/src/BootstrapBlazor.Server/Components/Samples/Tabs.razor
@@ -190,7 +190,7 @@ private void Navigation()
-
+
@Localizer["TabItem1Content"]
@@ -211,7 +211,7 @@ private void Navigation()
-
+
@Localizer["TabItem1Content"]
@@ -232,7 +232,7 @@ private void Navigation()
-
+
@Localizer["TabItem1Content"]
@@ -339,7 +339,7 @@ private void Navigation()
-
+
@Localizer["TabItem1Content"]
@@ -497,30 +497,21 @@ private void Navigation()
-
-
-
- @Localizer["TabItem1Content"]
-
-
-
- @Localizer["TabItem2Content"]
-
-
- @Localizer["TabItem3Content"]
-
-
- @Localizer["TabItem4Content"]
-
-
-
-
-
-
-
-
-
-
+
+
+ @Localizer["TabItem1Content"]
+
+
+
+ @Localizer["TabItem2Content"]
+
+
+ @Localizer["TabItem3Content"]
+
+
+ @Localizer["TabItem4Content"]
+
+
diff --git a/src/BootstrapBlazor.Server/Components/Samples/Tabs.razor.cs b/src/BootstrapBlazor.Server/Components/Samples/Tabs.razor.cs
index 737571a6762..38a899ca15f 100644
--- a/src/BootstrapBlazor.Server/Components/Samples/Tabs.razor.cs
+++ b/src/BootstrapBlazor.Server/Components/Samples/Tabs.razor.cs
@@ -13,7 +13,7 @@ public sealed partial class Tabs
[NotNull]
private Tab? TabSet { get; set; }
- private Placement BindPlacement = Placement.Top;
+ private Placement _bindPlacement = Placement.Top;
private bool RemoveEnabled => (TabSet?.Items.Count() ?? 4) < 4;
@@ -39,7 +39,7 @@ public sealed partial class Tabs
private void SetPlacement(Placement placement)
{
- BindPlacement = placement;
+ _bindPlacement = placement;
}
private Task AddTab(Tab tabset)
@@ -77,26 +77,21 @@ private static async Task RemoveTab(Tab tabset)
private void OnToggleDisable()
{
Disabled = !Disabled;
-
DisableText = Disabled ? "Enable" : "Disable";
}
///
- /// OnAfterRenderAsync
+ ///
///
///
- ///
- protected override async Task OnAfterRenderAsync(bool firstRender)
+ protected override void OnAfterRender(bool firstRender)
{
if (firstRender)
{
- var menuItem = TabMenu?.Items.FirstOrDefault();
- if (menuItem != null)
+ var menuItem = TabMenu.Items.FirstOrDefault();
+ if (menuItem != null && TabMenu.OnClick is not null)
{
- await InvokeAsync(() =>
- {
- var _ = TabMenu?.OnClick?.Invoke(menuItem);
- });
+ TabMenu.OnClick(menuItem);
}
}
}
@@ -123,11 +118,6 @@ private void AddTabItem(string text) => TabSetMenu.AddTab(new Dictionary().Render() : BootstrapDynamicComponent.CreateComponent().Render()
});
- private void OnClick()
- {
- ShowButtons = !ShowButtons;
- }
-
private async Task RemoveTab()
{
if (TabSetApp.Items.Count() > 4)
@@ -171,42 +161,6 @@ private Task OnSetTitle(string text)
return Task.CompletedTask;
}
- [NotNull]
- private Tab? _tab = null;
-
- private Task OnRefrsh(ContextMenuItem item, object? context)
- {
- if (context is TabItem tabItem)
- {
- _tab.Refresh(tabItem);
- }
- return Task.CompletedTask;
- }
-
- private async Task OnClose(ContextMenuItem item, object? context)
- {
- if (context is TabItem tabItem)
- {
- await _tab.RemoveTab(tabItem);
- }
- }
-
- private Task OnCloseOther(ContextMenuItem item, object? context)
- {
- if (context is TabItem tabItem)
- {
- _tab.ActiveTab(tabItem);
- }
- _tab.CloseOtherTabs();
- return Task.CompletedTask;
- }
-
- private Task OnCloseAll(ContextMenuItem item, object? context)
- {
- _tab.CloseAllTabs();
- return Task.CompletedTask;
- }
-
///
/// 获得属性方法
///
From 67373bd75ca40e66ab29612c6e6651d37f611824 Mon Sep 17 00:00:00 2001
From: Argo Zhang
Date: Fri, 28 Mar 2025 12:05:31 +0800
Subject: [PATCH 03/16] =?UTF-8?q?refactor:=20=E7=B2=BE=E7=AE=80=E4=BB=A3?=
=?UTF-8?q?=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Components/Layout/Layout.razor | 1 +
.../Components/Layout/Layout.razor.cs | 32 -------------------
2 files changed, 1 insertion(+), 32 deletions(-)
diff --git a/src/BootstrapBlazor/Components/Layout/Layout.razor b/src/BootstrapBlazor/Components/Layout/Layout.razor
index 67c3eda60cf..5e218e25aac 100644
--- a/src/BootstrapBlazor/Components/Layout/Layout.razor
+++ b/src/BootstrapBlazor/Components/Layout/Layout.razor
@@ -130,6 +130,7 @@
DefaultUrl="@TabDefaultUrl" ExcludeUrls="@ExcludeUrls" IsOnlyRenderActiveTab="IsOnlyRenderActiveTab"
TabStyle="TabStyle" ShowToolbar="@ShowToolbar" ToolbarTemplate="@ToolbarTemplate"
ShowContextMenu="ShowTabContextMenu"
+ BeforeContextMenuTemplate="@BeforeTabContextMenuTemplate" ContextMenuTemplate="@TabContextMenuTemplate"
ContextMenuRefreshIcon="@TabContextMenuRefreshIcon" ContextMenuCloseIcon="@TabContextMenuCloseIcon"
ContextMenuCloseOtherIcon="@TabContextMenuCloseOtherIcon" ContextMenuCloseAllIcon="@TabContextMenuCloseAllIcon"
ShowRefreshToolbarButton="ShowRefreshToolbarButton" ShowFullscreenToolbarButton="ShowFullscreenToolbarButton"
diff --git a/src/BootstrapBlazor/Components/Layout/Layout.razor.cs b/src/BootstrapBlazor/Components/Layout/Layout.razor.cs
index 187fbea59b6..286b4e5a299 100644
--- a/src/BootstrapBlazor/Components/Layout/Layout.razor.cs
+++ b/src/BootstrapBlazor/Components/Layout/Layout.razor.cs
@@ -623,38 +623,6 @@ public virtual Task HandlerException(Exception ex, RenderFragment err
private string? GetTargetString() => IsFixedTabHeader ? ".tabs-body" : null;
- private async Task OnRefresh(ContextMenuItem item, object? context)
- {
- if (context is TabItem tabItem)
- {
- await _tab.Refresh(tabItem);
- }
- }
-
- private async Task OnClose(ContextMenuItem item, object? context)
- {
- if (context is TabItem tabItem)
- {
- await _tab.RemoveTab(tabItem);
- }
- }
-
- private Task OnCloseOther(ContextMenuItem item, object? context)
- {
- if (context is TabItem tabItem)
- {
- _tab.ActiveTab(tabItem);
- }
- _tab.CloseOtherTabs();
- return Task.CompletedTask;
- }
-
- private Task OnCloseAll(ContextMenuItem item, object? context)
- {
- _tab.CloseAllTabs();
- return Task.CompletedTask;
- }
-
///
///
///
From fbbd4276e2a210a43f545ed37c0db1f663741d6a Mon Sep 17 00:00:00 2001
From: Argo Zhang
Date: Fri, 28 Mar 2025 12:51:46 +0800
Subject: [PATCH 04/16] =?UTF-8?q?refactor:=20=E4=BB=A3=E7=A0=81=E6=A0=BC?=
=?UTF-8?q?=E5=BC=8F=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/BootstrapBlazor/Components/Tab/Tab.razor.cs | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/BootstrapBlazor/Components/Tab/Tab.razor.cs b/src/BootstrapBlazor/Components/Tab/Tab.razor.cs
index fb38b933d1f..70c6bf7d7b3 100644
--- a/src/BootstrapBlazor/Components/Tab/Tab.razor.cs
+++ b/src/BootstrapBlazor/Components/Tab/Tab.razor.cs
@@ -358,13 +358,13 @@ public partial class Tab : IHandlerException
///
[Parameter]
public string? CloseTabNavLinkTooltipText { get; set; }
-
+
///
/// Gets or sets whether enable tab context menu. Default is false.
///
[Parameter]
public bool ShowContextMenu { get; set; }
-
+
///
/// Gets or sets the template of before context menu. Default is null.
///
@@ -376,7 +376,7 @@ public partial class Tab : IHandlerException
///
[Parameter]
public RenderFragment? ContextMenuTemplate { get; set; }
-
+
///
/// Gets or sets the icon of tab item context menu refresh button. Default is null.
///
@@ -400,7 +400,7 @@ public partial class Tab : IHandlerException
///
[Parameter]
public string? ContextMenuCloseAllIcon { get; set; }
-
+
[CascadingParameter]
private Layout? Layout { get; set; }
@@ -426,9 +426,9 @@ public partial class Tab : IHandlerException
[Inject, NotNull]
private DialogService? DialogService { get; set; }
-
+
private ContextMenuZone? _contextMenuZone;
-
+
private ConcurrentDictionary LazyTabCache { get; } = new();
private bool HandlerNavigation { get; set; }
@@ -484,7 +484,7 @@ protected override void OnParametersSet()
ContextMenuCloseIcon ??= IconTheme.GetIconByKey(ComponentIcons.TabContextMenuCloseIcon);
ContextMenuCloseOtherIcon ??= IconTheme.GetIconByKey(ComponentIcons.TabContextMenuCloseOtherIcon);
ContextMenuCloseAllIcon ??= IconTheme.GetIconByKey(ComponentIcons.TabContextMenuCloseAllIcon);
-
+
if (AdditionalAssemblies is null)
{
var entryAssembly = Assembly.GetEntryAssembly();
@@ -1035,7 +1035,7 @@ public async Task Refresh(TabItem item)
await OnToolbarRefreshCallback();
}
}
-
+
private async Task OnRefresh(ContextMenuItem item, object? context)
{
if (context is TabItem tabItem)
From ed77ae3c74e3197b39d067b6317a66ce1ebd08a7 Mon Sep 17 00:00:00 2001
From: Argo Zhang
Date: Fri, 28 Mar 2025 12:52:12 +0800
Subject: [PATCH 05/16] =?UTF-8?q?test:=20=E6=9B=B4=E6=96=B0=E5=8D=95?=
=?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
test/UnitTest/Components/LayoutTest.cs | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/test/UnitTest/Components/LayoutTest.cs b/test/UnitTest/Components/LayoutTest.cs
index e71b325142a..ecec738fd14 100644
--- a/test/UnitTest/Components/LayoutTest.cs
+++ b/test/UnitTest/Components/LayoutTest.cs
@@ -57,6 +57,14 @@ public async Task TabStyle_Ok()
cut.SetParametersAndRender(pb => pb.Add(a => a.TabContextMenuTemplate, tab => b => b.AddContent(0, "test-tab-context-menu")));
cut.Contains("test-tab-context-menu");
+ cut.SetParametersAndRender(pb =>
+ {
+ pb.Add(a => a.TabContextMenuRefreshIcon, "test-tab-refresh-icon");
+ pb.Add(a => a.TabContextMenuCloseIcon, "test-tab-close-icon");
+ pb.Add(a => a.TabContextMenuCloseAllIcon, "test-tab-close-all-icon");
+ pb.Add(a => a.TabContextMenuCloseOtherIcon, "test-tab-close-other-icon");
+ });
+
// test context menu onclick event handler
var tab = cut.Find(".tabs-item");
await cut.InvokeAsync(() => tab.ContextMenu());
@@ -66,6 +74,10 @@ public async Task TabStyle_Ok()
{
await cut.InvokeAsync(() => button.Click());
}
+ cut.Contains("test-tab-refresh-icon");
+ cut.Contains("test-tab-close-icon");
+ cut.Contains("test-tab-close-all-icon");
+ cut.Contains("test-tab-close-other-icon");
}
[Fact]
From fe5dcd546b220410e9a48f8550073d2707f24718 Mon Sep 17 00:00:00 2001
From: Argo Zhang
Date: Fri, 28 Mar 2025 13:05:27 +0800
Subject: [PATCH 06/16] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E4=BB=A3?=
=?UTF-8?q?=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Components/Samples/Tabs.razor.cs | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/src/BootstrapBlazor.Server/Components/Samples/Tabs.razor.cs b/src/BootstrapBlazor.Server/Components/Samples/Tabs.razor.cs
index 38a899ca15f..11ec89b6d0d 100644
--- a/src/BootstrapBlazor.Server/Components/Samples/Tabs.razor.cs
+++ b/src/BootstrapBlazor.Server/Components/Samples/Tabs.razor.cs
@@ -42,10 +42,10 @@ private void SetPlacement(Placement placement)
_bindPlacement = placement;
}
- private Task AddTab(Tab tabset)
+ private Task AddTab(Tab tab)
{
- var text = $"Tab {tabset.Items.Count() + 1}";
- tabset.AddTab(new Dictionary
+ var text = $"Tab {tab.Items.Count() + 1}";
+ tab.AddTab(new Dictionary
{
[nameof(TabItem.Text)] = text,
[nameof(TabItem.IsActive)] = true,
@@ -59,18 +59,18 @@ private Task AddTab(Tab tabset)
return Task.CompletedTask;
}
- private static Task Active(Tab tabset)
+ private static Task Active(Tab tab)
{
- tabset.ActiveTab(0);
+ tab.ActiveTab(0);
return Task.CompletedTask;
}
- private static async Task RemoveTab(Tab tabset)
+ private static async Task RemoveTab(Tab tab)
{
- if (tabset.Items.Count() > 4)
+ if (tab.Items.Count() > 4)
{
- var item = tabset.Items.Last();
- await tabset.RemoveTab(item);
+ var item = tab.Items.Last();
+ await tab.RemoveTab(item);
}
}
From bfd0dcec1678d678b8edab3512b93294eb1171e1 Mon Sep 17 00:00:00 2001
From: Argo Zhang
Date: Fri, 28 Mar 2025 13:09:59 +0800
Subject: [PATCH 07/16] =?UTF-8?q?refactor:=20=E6=95=B4=E7=90=86=E4=BB=A3?=
=?UTF-8?q?=E7=A0=81=E9=A1=BA=E5=BA=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/BootstrapBlazor/Components/Tab/Tab.razor.cs | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/BootstrapBlazor/Components/Tab/Tab.razor.cs b/src/BootstrapBlazor/Components/Tab/Tab.razor.cs
index 70c6bf7d7b3..0db12294b57 100644
--- a/src/BootstrapBlazor/Components/Tab/Tab.razor.cs
+++ b/src/BootstrapBlazor/Components/Tab/Tab.razor.cs
@@ -1068,6 +1068,14 @@ private Task OnCloseAll(ContextMenuItem item, object? context)
return Task.CompletedTask;
}
+ private async Task OnContextMenu(MouseEventArgs e, TabItem item)
+ {
+ if (_contextMenuZone != null && item is { Closable: true })
+ {
+ await _contextMenuZone.OnContextMenu(e, item);
+ }
+ }
+
///
///
///
@@ -1081,12 +1089,4 @@ protected override async ValueTask DisposeAsync(bool disposing)
ErrorLogger?.UnRegister(this);
}
}
-
- private async Task OnContextMenu(MouseEventArgs e, TabItem item)
- {
- if (_contextMenuZone != null)
- {
- await _contextMenuZone.OnContextMenu(e, item);
- }
- }
}
From 87b836c21181d787b05bc899fa5388f1737ddc54 Mon Sep 17 00:00:00 2001
From: Argo Zhang
Date: Fri, 28 Mar 2025 13:22:12 +0800
Subject: [PATCH 08/16] =?UTF-8?q?feat:=20=E7=A6=81=E7=94=A8=E6=A0=87?=
=?UTF-8?q?=E7=AD=BE=E9=A1=B5=E5=85=81=E8=AE=B8=E5=BC=B9=E5=87=BA=E5=8F=B3?=
=?UTF-8?q?=E9=94=AE=E8=8F=9C=E5=8D=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/BootstrapBlazor/Components/Tab/Tab.razor | 5 +++--
.../Components/Tab/Tab.razor.cs | 19 +++++++++++++++++--
2 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/src/BootstrapBlazor/Components/Tab/Tab.razor b/src/BootstrapBlazor/Components/Tab/Tab.razor
index a3afbe07197..a9de8d62912 100644
--- a/src/BootstrapBlazor/Components/Tab/Tab.razor
+++ b/src/BootstrapBlazor/Components/Tab/Tab.razor
@@ -188,9 +188,10 @@ else
@RenderTabItemContent(item)
;
- RenderFragment RenderDisabledHeaderItem(TabItem item) =>
+ RenderFragment RenderDisabledHeaderItem(TabItem item) =>
@
-
+
OnContextMenu(e, item)" @oncontextmenu:preventDefault="IsPreventDefault">
@RenderHeaderItemContent(item)
@if (TabStyle == TabStyle.Chrome)
diff --git a/src/BootstrapBlazor/Components/Tab/Tab.razor.cs b/src/BootstrapBlazor/Components/Tab/Tab.razor.cs
index 0db12294b57..e36f67e2790 100644
--- a/src/BootstrapBlazor/Components/Tab/Tab.razor.cs
+++ b/src/BootstrapBlazor/Components/Tab/Tab.razor.cs
@@ -400,6 +400,12 @@ public partial class Tab : IHandlerException
///
[Parameter]
public string? ContextMenuCloseAllIcon { get; set; }
+
+ ///
+ /// Gets or sets before popup context menu callback. Default is null.
+ ///
+ [Parameter]
+ public Func
>? OnBeforeShowContextMenu { get; set; }
[CascadingParameter]
private Layout? Layout { get; set; }
@@ -1070,9 +1076,18 @@ private Task OnCloseAll(ContextMenuItem item, object? context)
private async Task OnContextMenu(MouseEventArgs e, TabItem item)
{
- if (_contextMenuZone != null && item is { Closable: true })
+ if (_contextMenuZone != null)
{
- await _contextMenuZone.OnContextMenu(e, item);
+ var show = true;
+ if (OnBeforeShowContextMenu != null)
+ {
+ show = await OnBeforeShowContextMenu(item);
+ }
+
+ if (show)
+ {
+ await _contextMenuZone.OnContextMenu(e, item);
+ }
}
}
From de864bf502da0ddcedcb38906d497550f089db11 Mon Sep 17 00:00:00 2001
From: Argo Zhang
Date: Fri, 28 Mar 2025 14:11:47 +0800
Subject: [PATCH 09/16] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20OnBeforeShow?=
=?UTF-8?q?ContextMenu=20=E5=9B=9E=E8=B0=83=E6=96=B9=E6=B3=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/BootstrapBlazor/Components/Layout/Layout.razor | 1 +
src/BootstrapBlazor/Components/Layout/Layout.razor.cs | 6 ++++++
2 files changed, 7 insertions(+)
diff --git a/src/BootstrapBlazor/Components/Layout/Layout.razor b/src/BootstrapBlazor/Components/Layout/Layout.razor
index 5e218e25aac..75d823a6a9e 100644
--- a/src/BootstrapBlazor/Components/Layout/Layout.razor
+++ b/src/BootstrapBlazor/Components/Layout/Layout.razor
@@ -133,6 +133,7 @@
BeforeContextMenuTemplate="@BeforeTabContextMenuTemplate" ContextMenuTemplate="@TabContextMenuTemplate"
ContextMenuRefreshIcon="@TabContextMenuRefreshIcon" ContextMenuCloseIcon="@TabContextMenuCloseIcon"
ContextMenuCloseOtherIcon="@TabContextMenuCloseOtherIcon" ContextMenuCloseAllIcon="@TabContextMenuCloseAllIcon"
+ OnBeforeShowContextMenu="@OnBeforeShowContextMenu"
ShowRefreshToolbarButton="ShowRefreshToolbarButton" ShowFullscreenToolbarButton="ShowFullscreenToolbarButton"
RefreshToolbarButtonIcon="@RefreshToolbarButtonIcon" FullscreenToolbarButtonIcon="@FullscreenToolbarButtonIcon"
RefreshToolbarTooltipText="@RefreshToolbarTooltipText" FullscreenToolbarTooltipText="@FullscreenToolbarTooltipText"
diff --git a/src/BootstrapBlazor/Components/Layout/Layout.razor.cs b/src/BootstrapBlazor/Components/Layout/Layout.razor.cs
index 286b4e5a299..3e68e58ffad 100644
--- a/src/BootstrapBlazor/Components/Layout/Layout.razor.cs
+++ b/src/BootstrapBlazor/Components/Layout/Layout.razor.cs
@@ -339,6 +339,12 @@ public partial class Layout : IHandlerException
[Parameter]
public string? TabContextMenuCloseAllIcon { get; set; }
+ ///
+ /// Gets or sets before popup context menu callback. Default is null.
+ ///
+ [Parameter]
+ public Func>? OnBeforeShowContextMenu { get; set; }
+
[Inject]
[NotNull]
private NavigationManager? Navigation { get; set; }
From 128ea9f7268005154541cc019383d5148a0ffdfc Mon Sep 17 00:00:00 2001
From: Argo Zhang
Date: Fri, 28 Mar 2025 14:17:37 +0800
Subject: [PATCH 10/16] =?UTF-8?q?doc:=20=E6=9B=B4=E6=96=B0=E7=A4=BA?=
=?UTF-8?q?=E4=BE=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/BootstrapBlazor.Server/Components/Samples/Tabs.razor | 8 ++++++--
.../Components/Samples/Tabs.razor.cs | 6 ++++++
src/BootstrapBlazor.Server/Locales/en-US.json | 3 ++-
src/BootstrapBlazor.Server/Locales/zh-CN.json | 3 ++-
4 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/src/BootstrapBlazor.Server/Components/Samples/Tabs.razor b/src/BootstrapBlazor.Server/Components/Samples/Tabs.razor
index 824638445f9..4e4720d6cfc 100644
--- a/src/BootstrapBlazor.Server/Components/Samples/Tabs.razor
+++ b/src/BootstrapBlazor.Server/Components/Samples/Tabs.razor
@@ -497,8 +497,12 @@ private void Navigation()
-
-
+
+ @((MarkupString)Localizer["TabsContextMenuDesc"].Value)
+
+
+
@Localizer["TabItem1Content"]
diff --git a/src/BootstrapBlazor.Server/Components/Samples/Tabs.razor.cs b/src/BootstrapBlazor.Server/Components/Samples/Tabs.razor.cs
index 11ec89b6d0d..f84abb3028d 100644
--- a/src/BootstrapBlazor.Server/Components/Samples/Tabs.razor.cs
+++ b/src/BootstrapBlazor.Server/Components/Samples/Tabs.razor.cs
@@ -111,6 +111,12 @@ private Task OnClickMenuItem(MenuItem item)
return Task.CompletedTask;
}
+ private async Task OnBeforeShowContextMenu(TabItem item)
+ {
+ await Task.Yield();
+ return item.IsDisabled == false;
+ }
+
private void AddTabItem(string text) => TabSetMenu.AddTab(new Dictionary
{
[nameof(TabItem.Text)] = text,
diff --git a/src/BootstrapBlazor.Server/Locales/en-US.json b/src/BootstrapBlazor.Server/Locales/en-US.json
index 83e167868de..f1f668c3a12 100644
--- a/src/BootstrapBlazor.Server/Locales/en-US.json
+++ b/src/BootstrapBlazor.Server/Locales/en-US.json
@@ -2138,7 +2138,8 @@
"ContextCloseOther": "Close Other Tabs",
"ContextCloseAll": "Close All Tabs",
"TabsContextMenuTitle": "TabItem Context Menu",
- "TabsContextMenuIntro": "Use the built-in ContextMenuZone component to pop up a custom context menu when you right-click a tab item"
+ "TabsContextMenuIntro": "Use the built-in ContextMenuZone component to pop up a custom context menu when you right-click a tab item",
+ "TabsContextMenuDesc": "For disabled tabs, you can set the OnBeforeShowContextMenu callback method to control whether the right-click menu is displayed. By default, it is displayed."
},
"BootstrapBlazor.Server.Components.Components.DemoTabItem": {
"Info": "Reset the title of this TabItem by click the button",
diff --git a/src/BootstrapBlazor.Server/Locales/zh-CN.json b/src/BootstrapBlazor.Server/Locales/zh-CN.json
index ee4b22c87e9..113b1601966 100644
--- a/src/BootstrapBlazor.Server/Locales/zh-CN.json
+++ b/src/BootstrapBlazor.Server/Locales/zh-CN.json
@@ -2138,7 +2138,8 @@
"ContextCloseOther": "关闭其他",
"ContextCloseAll": "关闭全部",
"TabsContextMenuTitle": "右键菜单",
- "TabsContextMenuIntro": "通过内置 ContextMenuZone 组件,点击标签页右键时弹窗自定义右键菜单"
+ "TabsContextMenuIntro": "通过内置 ContextMenuZone 组件,点击标签页右键时弹窗自定义右键菜单",
+ "TabsContextMenuDesc": "被禁用的标签页可以通过设置 OnBeforeShowContextMenu 回调方法控制右键菜单是否显示,默认均显示"
},
"BootstrapBlazor.Server.Components.Components.DemoTabItem": {
"Info": "点击下方按钮,本 TabItem 标题更改为当前分钟与秒",
From a6862df979b2da0f2ec7d21cf6e86e1db85d49ac Mon Sep 17 00:00:00 2001
From: Argo Zhang
Date: Fri, 28 Mar 2025 14:19:12 +0800
Subject: [PATCH 11/16] =?UTF-8?q?doc:=20=E6=9B=B4=E6=96=B0=E8=AF=B4?=
=?UTF-8?q?=E6=98=8E=E6=96=87=E5=AD=97?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/BootstrapBlazor.Server/Locales/en-US.json | 2 +-
src/BootstrapBlazor.Server/Locales/zh-CN.json | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/BootstrapBlazor.Server/Locales/en-US.json b/src/BootstrapBlazor.Server/Locales/en-US.json
index f1f668c3a12..38c3ac9e39a 100644
--- a/src/BootstrapBlazor.Server/Locales/en-US.json
+++ b/src/BootstrapBlazor.Server/Locales/en-US.json
@@ -2139,7 +2139,7 @@
"ContextCloseAll": "Close All Tabs",
"TabsContextMenuTitle": "TabItem Context Menu",
"TabsContextMenuIntro": "Use the built-in ContextMenuZone component to pop up a custom context menu when you right-click a tab item",
- "TabsContextMenuDesc": "For disabled tabs, you can set the OnBeforeShowContextMenu callback method to control whether the right-click menu is displayed. By default, it is displayed."
+ "TabsContextMenuDesc": "The disabled tab can be set by setting the OnBeforeShowContextMenu callback method to control whether the right-click menu is displayed according to the return value. If it is not set, the right-click menu is also displayed for the disabled tab"
},
"BootstrapBlazor.Server.Components.Components.DemoTabItem": {
"Info": "Reset the title of this TabItem by click the button",
diff --git a/src/BootstrapBlazor.Server/Locales/zh-CN.json b/src/BootstrapBlazor.Server/Locales/zh-CN.json
index 113b1601966..42580fe6dad 100644
--- a/src/BootstrapBlazor.Server/Locales/zh-CN.json
+++ b/src/BootstrapBlazor.Server/Locales/zh-CN.json
@@ -2139,7 +2139,7 @@
"ContextCloseAll": "关闭全部",
"TabsContextMenuTitle": "右键菜单",
"TabsContextMenuIntro": "通过内置 ContextMenuZone 组件,点击标签页右键时弹窗自定义右键菜单",
- "TabsContextMenuDesc": "被禁用的标签页可以通过设置 OnBeforeShowContextMenu 回调方法控制右键菜单是否显示,默认均显示"
+ "TabsContextMenuDesc": "被禁用的标签页可以通过设置 OnBeforeShowContextMenu 回调方法根据返回值控制右键菜单是否显示,未设置时禁用标签页也显示右键菜单"
},
"BootstrapBlazor.Server.Components.Components.DemoTabItem": {
"Info": "点击下方按钮,本 TabItem 标题更改为当前分钟与秒",
From 6544bedc3a7dcc6464aeb00f2a1776e29cc2d7d4 Mon Sep 17 00:00:00 2001
From: Argo Zhang
Date: Fri, 28 Mar 2025 14:21:03 +0800
Subject: [PATCH 12/16] =?UTF-8?q?test:=20=E6=9B=B4=E6=96=B0=E5=8D=95?=
=?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
test/UnitTest/Components/LayoutTest.cs | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/test/UnitTest/Components/LayoutTest.cs b/test/UnitTest/Components/LayoutTest.cs
index ecec738fd14..0d129c591a8 100644
--- a/test/UnitTest/Components/LayoutTest.cs
+++ b/test/UnitTest/Components/LayoutTest.cs
@@ -78,6 +78,18 @@ public async Task TabStyle_Ok()
cut.Contains("test-tab-close-icon");
cut.Contains("test-tab-close-all-icon");
cut.Contains("test-tab-close-other-icon");
+
+ var show = false;
+ cut.SetParametersAndRender(pb =>
+ {
+ pb.Add(a => a.OnBeforeShowContextMenu, item =>
+ {
+ show = true;
+ return Task.FromResult(true);
+ });
+ });
+ await cut.InvokeAsync(() => tab.ContextMenu());
+ Assert.True(show);
}
[Fact]
From d17442e2184cbf987c3904a8339ff3aa6a7ef8f4 Mon Sep 17 00:00:00 2001
From: Argo Zhang
Date: Fri, 28 Mar 2025 14:33:05 +0800
Subject: [PATCH 13/16] =?UTF-8?q?test:=20=E6=9B=B4=E6=96=B0=E5=8D=95?=
=?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
test/UnitTest/Components/TabTest.cs | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/test/UnitTest/Components/TabTest.cs b/test/UnitTest/Components/TabTest.cs
index b78809bb9ed..1365e819bb6 100644
--- a/test/UnitTest/Components/TabTest.cs
+++ b/test/UnitTest/Components/TabTest.cs
@@ -496,13 +496,16 @@ public async Task IsDisabled_Ok()
pb.AddChildContent();
});
});
- Assert.Contains("", cut.Markup);
+ var tabItems = cut.FindAll(".tabs-item");
+ Assert.Contains("tabs-item disabled", tabItems[0].OuterHtml);
+ Assert.DoesNotContain("tabs-item disabled", tabItems[1].OuterHtml);
var button = cut.FindComponent();
Assert.NotNull(button);
await cut.InvokeAsync(() => button.Instance.OnDisabledTabItem());
- Assert.Contains("", cut.Markup);
+ tabItems = cut.FindAll(".tabs-item");
+ Assert.Contains("tabs-item disabled", tabItems[1].OuterHtml);
}
[Fact]
From d783b5006b17b8fd8fb07fe72dd430a85dcf1a2d Mon Sep 17 00:00:00 2001
From: Argo Zhang
Date: Fri, 28 Mar 2025 14:33:57 +0800
Subject: [PATCH 14/16] =?UTF-8?q?test:=20=E6=9B=B4=E6=96=B0=E5=8D=95?=
=?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
test/UnitTest/Components/TabTest.cs | 5 -----
1 file changed, 5 deletions(-)
diff --git a/test/UnitTest/Components/TabTest.cs b/test/UnitTest/Components/TabTest.cs
index 1365e819bb6..7f0ee961d05 100644
--- a/test/UnitTest/Components/TabTest.cs
+++ b/test/UnitTest/Components/TabTest.cs
@@ -545,11 +545,6 @@ public async Task TabStyle_Chrome_Ok()
cut.Contains("");
cut.Contains("");
- var button = cut.FindComponent();
- Assert.NotNull(button);
- await cut.InvokeAsync(() => button.Instance.OnDisabledTabItem());
- cut.Contains("");
-
// trigger click
var link = cut.Find("a");
await cut.InvokeAsync(() => link.Click());
From b56d7c7e44739866c01259d3551e6980ce89cc94 Mon Sep 17 00:00:00 2001
From: Argo Zhang
Date: Fri, 28 Mar 2025 14:37:32 +0800
Subject: [PATCH 15/16] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E4=BB=A3?=
=?UTF-8?q?=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/BootstrapBlazor/Components/Tab/Tab.razor.cs | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/BootstrapBlazor/Components/Tab/Tab.razor.cs b/src/BootstrapBlazor/Components/Tab/Tab.razor.cs
index e36f67e2790..21610165ab0 100644
--- a/src/BootstrapBlazor/Components/Tab/Tab.razor.cs
+++ b/src/BootstrapBlazor/Components/Tab/Tab.razor.cs
@@ -400,7 +400,7 @@ public partial class Tab : IHandlerException
///
[Parameter]
public string? ContextMenuCloseAllIcon { get; set; }
-
+
///
/// Gets or sets before popup context menu callback. Default is null.
///
@@ -942,9 +942,10 @@ public void SetDisabledItem(TabItem item, bool disabled)
{
item.SetActive(false);
}
- if (TabItems.Any(i => i.IsActive) == false)
+ if (TabItems.Find(i => i.IsActive) == null)
{
- TabItems.FirstOrDefault(i => !i.IsDisabled)?.SetActive(true);
+ var tabItem = TabItems.Find(i => !i.IsDisabled);
+ tabItem?.SetActive(true);
}
StateHasChanged();
}
From 5cc9cf52b66d6a4ce1007187e975be0889a680c7 Mon Sep 17 00:00:00 2001
From: Argo Zhang
Date: Fri, 28 Mar 2025 14:45:59 +0800
Subject: [PATCH 16/16] =?UTF-8?q?test:=20=E6=9B=B4=E6=96=B0=E5=8D=95?=
=?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
test/UnitTest/Components/TabTest.cs | 26 +++++++-------------------
1 file changed, 7 insertions(+), 19 deletions(-)
diff --git a/test/UnitTest/Components/TabTest.cs b/test/UnitTest/Components/TabTest.cs
index 7f0ee961d05..99df42b4fc2 100644
--- a/test/UnitTest/Components/TabTest.cs
+++ b/test/UnitTest/Components/TabTest.cs
@@ -28,13 +28,14 @@ protected override void ConfigureServices(IServiceCollection services)
[Fact]
public async Task ContextMenu_Ok()
{
- var clicked = false;
var cut = Context.RenderComponent(pb =>
{
pb.AddChildContent(pb =>
{
+ pb.Add(a => a.ShowContextMenu, true);
pb.AddChildContent(pb =>
{
+ pb.Add(a => a.IsDisabled, true);
pb.Add(a => a.Text, "Tab1");
pb.Add(a => a.Url, "/Index");
pb.Add(a => a.Closable, true);
@@ -42,30 +43,13 @@ public async Task ContextMenu_Ok()
pb.Add(a => a.ChildContent, "Tab1-Content");
});
});
- pb.AddChildContent(pb =>
- {
- pb.AddChildContent(pb =>
- {
- pb.Add(a => a.Text, "test-close");
- pb.Add(a => a.OnClick, (context, item) =>
- {
- clicked = true;
- if (item is TabItem tabItem)
- {
-
- }
- return Task.CompletedTask;
- });
- });
- });
});
var menuItem = cut.Find(".tabs-item");
await cut.InvokeAsync(() => menuItem.ContextMenu());
var item = cut.Find(".dropdown-menu .dropdown-item");
- await cut.InvokeAsync(() => item.Click());
- Assert.True(clicked);
+ Assert.NotNull(item);
}
[Fact]
@@ -545,6 +529,10 @@ public async Task TabStyle_Chrome_Ok()
cut.Contains("");
cut.Contains("");
+ var button = cut.FindComponent();
+ Assert.NotNull(button);
+ await cut.InvokeAsync(() => button.Instance.OnDisabledTabItem());
+
// trigger click
var link = cut.Find("a");
await cut.InvokeAsync(() => link.Click());