diff --git a/src/BootstrapBlazor.Server/Components/Samples/Tabs.razor b/src/BootstrapBlazor.Server/Components/Samples/Tabs.razor index 4b1c93add90..fd3fb2ca47d 100644 --- a/src/BootstrapBlazor.Server/Components/Samples/Tabs.razor +++ b/src/BootstrapBlazor.Server/Components/Samples/Tabs.razor @@ -501,6 +501,7 @@ private void Navigation() @Localizer["TabItem1Content"] + @Localizer["TabItem2Content"] @@ -513,6 +514,8 @@ private void Navigation() + + diff --git a/src/BootstrapBlazor.Server/Components/Samples/Tabs.razor.cs b/src/BootstrapBlazor.Server/Components/Samples/Tabs.razor.cs index 77eb539f128..737571a6762 100644 --- a/src/BootstrapBlazor.Server/Components/Samples/Tabs.razor.cs +++ b/src/BootstrapBlazor.Server/Components/Samples/Tabs.razor.cs @@ -174,6 +174,15 @@ private Task OnSetTitle(string text) [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) diff --git a/src/BootstrapBlazor.Server/Locales/en-US.json b/src/BootstrapBlazor.Server/Locales/en-US.json index 20eb4918929..024244ffdbe 100644 --- a/src/BootstrapBlazor.Server/Locales/en-US.json +++ b/src/BootstrapBlazor.Server/Locales/en-US.json @@ -2133,6 +2133,7 @@ "AttributeFullscreenToolbarButtonIcon": "Toolbar full screen button icon", "TabsToolbarDesc": "After clicking the button, the counter value increases, and clicking the Refresh button on the toolbar will reset the counter.", "AttributeOnToolbarRefreshCallback": "Click the toolbar refresh button callback method", + "ContextRefresh": "Refresh", "ContextClose": "Close", "ContextCloseOther": "Close Other Tabs", "ContextCloseAll": "Close All Tabs", diff --git a/src/BootstrapBlazor.Server/Locales/zh-CN.json b/src/BootstrapBlazor.Server/Locales/zh-CN.json index b30f29bf7ac..ee4b22c87e9 100644 --- a/src/BootstrapBlazor.Server/Locales/zh-CN.json +++ b/src/BootstrapBlazor.Server/Locales/zh-CN.json @@ -2133,6 +2133,7 @@ "AttributeFullscreenToolbarButtonIcon": "工具栏全屏按钮图标", "TabsToolbarDesc": "点击按钮计数器数值增加后,点击工具栏的 刷新 按钮计数器清零", "AttributeOnToolbarRefreshCallback": "点击工具栏刷新按钮回调方法", + "ContextRefresh": "刷新", "ContextClose": "关闭", "ContextCloseOther": "关闭其他", "ContextCloseAll": "关闭全部", diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index c7a6b4e7fe6..83172568a14 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@ - 9.5.0-beta12 + 9.5.0-beta13 diff --git a/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor.scss b/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor.scss index 9fe4719f40d..3d8e6cc4eef 100644 --- a/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor.scss +++ b/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor.scss @@ -8,4 +8,8 @@ min-height: var(--bb-cm-icon-min-height); display: inline-block; } + + .divider { + margin: 0.5rem 0; + } } diff --git a/src/BootstrapBlazor/Components/Tab/Tab.razor.cs b/src/BootstrapBlazor/Components/Tab/Tab.razor.cs index 33aebffd200..be2cf1bc303 100644 --- a/src/BootstrapBlazor/Components/Tab/Tab.razor.cs +++ b/src/BootstrapBlazor/Components/Tab/Tab.razor.cs @@ -950,6 +950,19 @@ private async Task OnRefreshAsync() { // refresh the active tab item var item = TabItems.FirstOrDefault(i => i.IsActive); + + if (item is not null) + { + await Refresh(item); + } + } + + /// + /// Refresh the tab item method + /// + /// + public async Task Refresh(TabItem item) + { item.Refresh(_cache); if (OnToolbarRefreshCallback != null) diff --git a/src/BootstrapBlazor/Extensions/TabItemExtensions.cs b/src/BootstrapBlazor/Extensions/TabItemExtensions.cs index 75abc1a3391..d4236a96051 100644 --- a/src/BootstrapBlazor/Extensions/TabItemExtensions.cs +++ b/src/BootstrapBlazor/Extensions/TabItemExtensions.cs @@ -24,9 +24,9 @@ public static RenderFragment RenderContent(this TabItem item, ConcurrentDictiona builder.CloseComponent(); }; - public static void Refresh(this TabItem? item, ConcurrentDictionary cache) + public static void Refresh(this TabItem item, ConcurrentDictionary cache) { - if (item is not null && cache.TryGetValue(item, out var content)) + if (cache.TryGetValue(item, out var content)) { content.Render(); } diff --git a/test/UnitTest/Components/TabTest.cs b/test/UnitTest/Components/TabTest.cs index f32d7dbe880..48c013f74f4 100644 --- a/test/UnitTest/Components/TabTest.cs +++ b/test/UnitTest/Components/TabTest.cs @@ -7,7 +7,6 @@ using Bunit.TestDoubles; using Microsoft.AspNetCore.Components.Rendering; using System.Reflection; -using System.Threading.Tasks; using UnitTest.Misc; namespace UnitTest.Components; @@ -1100,6 +1099,11 @@ public async Task ShowToolbar_Ok() await cut.InvokeAsync(() => button.Click()); Assert.True(clicked); + clicked = false; + var item = cut.FindComponent(); + await cut.InvokeAsync(() => tab.Instance.Refresh(item.Instance)); + Assert.True(clicked); + tab.SetParametersAndRender(pb => { pb.Add(a => a.ShowRefreshToolbarButton, false); @@ -1111,13 +1115,6 @@ public async Task ShowToolbar_Ok() pb.Add(a => a.ShowFullscreenToolbarButton, false); }); cut.DoesNotContain("tabs-nav-toolbar-fs"); - - // 利用反射提高代码覆盖率 - var type = Type.GetType("BootstrapBlazor.Components.TabItemExtensions, BootstrapBlazor"); - Assert.NotNull(type); - var mi = type.GetMethod("Refresh", BindingFlags.Static | BindingFlags.Public); - Assert.NotNull(mi); - mi.Invoke(null, [null, null]); } class DisableTabItemButton : ComponentBase