Skip to content

Commit 5330eec

Browse files
authored
feat(Layout): add OnTabHeaderTextLocalizer parameter (#7070)
* feat(Layout): add OnTabHeaderTextLocalizer parameter * refactor: 重构代码 * chore: bump version 9.12.2-beta03 * test: 增加单元测试 * refactor: 重构代码 * refactor: 精简代码
1 parent 986f8d5 commit 5330eec

File tree

5 files changed

+27
-14
lines changed

5 files changed

+27
-14
lines changed

src/BootstrapBlazor/BootstrapBlazor.csproj

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

33
<PropertyGroup Condition="'$(VisualStudioVersion)' == '17.0'">
4-
<Version>9.12.2-beta02</Version>
4+
<Version>9.12.2-beta03</Version>
55
</PropertyGroup>
66

77
<PropertyGroup Condition="'$(VisualStudioVersion)' == '18.0'">
8-
<Version>10.0.0-rc.2.2.4</Version>
8+
<Version>10.0.0-rc.2.2.5</Version>
99
</PropertyGroup>
1010

1111
<ItemGroup>

src/BootstrapBlazor/Components/Layout/Layout.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
ShowExtendButtons="ShowTabExtendButtons" ShowClose="ShowTabItemClose" AllowDrag="AllowDragTab"
139139
DefaultUrl="@TabDefaultUrl" ExcludeUrls="@ExcludeUrls" IsOnlyRenderActiveTab="IsOnlyRenderActiveTab"
140140
TabStyle="TabStyle" ShowToolbar="@ShowToolbar" ToolbarTemplate="@ToolbarTemplate"
141-
ShowContextMenu="ShowTabContextMenu"
141+
ShowContextMenu="ShowTabContextMenu" OnTabHeaderTextLocalizer="OnTabHeaderTextLocalizer"
142142
BeforeContextMenuTemplate="@BeforeTabContextMenuTemplate" ContextMenuTemplate="@TabContextMenuTemplate"
143143
ContextMenuRefreshIcon="@TabContextMenuRefreshIcon" ContextMenuCloseIcon="@TabContextMenuCloseIcon"
144144
ContextMenuCloseOtherIcon="@TabContextMenuCloseOtherIcon" ContextMenuCloseAllIcon="@TabContextMenuCloseAllIcon"

src/BootstrapBlazor/Components/Layout/Layout.razor.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ public partial class Layout : IHandlerException, ITabHeader
1818
{
1919
private bool IsSmallScreen { get; set; }
2020

21+
/// <summary>
22+
/// 获得/设置 Tab 标签头文本本地化回调方法
23+
/// </summary>
24+
[Parameter]
25+
public Func<string?, string?>? OnTabHeaderTextLocalizer { get; set; }
26+
2127
/// <summary>
2228
/// Gets or sets the tab style. Default is <see cref="TabStyle.Default"/>.
2329
/// </summary>

src/BootstrapBlazor/Components/Tab/Tab.razor.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
@@ -197,7 +197,6 @@ public partial class Tab
197197
/// 获得/设置 Gets or sets a collection of additional assemblies that should be searched for components that can match URIs.
198198
/// </summary>
199199
[Parameter]
200-
[NotNull]
201200
public IEnumerable<Assembly>? AdditionalAssemblies { get; set; }
202201

203202
/// <summary>
@@ -529,15 +528,6 @@ protected override void OnParametersSet()
529528
ContextMenuCloseAllIcon ??= IconTheme.GetIconByKey(ComponentIcons.TabContextMenuCloseAllIcon);
530529
ContextMenuFullScreenIcon ??= IconTheme.GetIconByKey(ComponentIcons.TabContextMenuFullScreenIcon);
531530

532-
if (AdditionalAssemblies is null)
533-
{
534-
var entryAssembly = Assembly.GetEntryAssembly();
535-
if (entryAssembly is not null)
536-
{
537-
AdditionalAssemblies = [entryAssembly];
538-
}
539-
}
540-
541531
if (Placement != Placement.Top && TabStyle == TabStyle.Chrome)
542532
{
543533
TabStyle = TabStyle.Default;
@@ -816,6 +806,7 @@ public void AddTab(string url, string text, string? icon = null, bool active = t
816806

817807
private void AddTabItem(string url)
818808
{
809+
AdditionalAssemblies ??= [Assembly.GetEntryAssembly()!];
819810
var parameters = new Dictionary<string, object?>
820811
{
821812
{ nameof(TabItem.Url), url }

test/UnitTest/Components/LayoutTest.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,22 @@ public async Task TabStyle_Ok()
9393
Assert.True(show);
9494
}
9595

96+
[Fact]
97+
public void OnTabHeaderTextLocalizer_Ok()
98+
{
99+
var cut = Context.RenderComponent<Layout>(pb =>
100+
{
101+
pb.Add(a => a.UseTabSet, true);
102+
pb.Add(a => a.AdditionalAssemblies, new Assembly[] { GetType().Assembly });
103+
pb.Add(a => a.OnTabHeaderTextLocalizer, text => $"Localized-{text}");
104+
});
105+
106+
var nav = cut.Services.GetRequiredService<FakeNavigationManager>();
107+
nav.NavigateTo("/Cat");
108+
109+
cut.Contains("Localized-Cat");
110+
}
111+
96112
[Fact]
97113
public async Task ShowTabInHeader_Ok()
98114
{

0 commit comments

Comments
 (0)