Skip to content

Commit b5fbcfd

Browse files
authored
feat(Tab): add OnToolbarRefreshCallback parameter (#5696)
* feat: 增加 OnToolbarRefreshCallback 回调方法 * doc: 更新文档 * doc: 增加刷新按钮回调方法文档说明 * doc: 更新文档 * refactor: 更新 TooltipTrigger 值为 hover
1 parent cbcfba4 commit b5fbcfd

File tree

8 files changed

+43
-11
lines changed

8 files changed

+43
-11
lines changed

src/BootstrapBlazor.Server/Components/Samples/Tabs.razor

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,6 @@ private void Navigation()
457457
<Tab IsCard="true" ShowClose="true" TabStyle="TabStyle.Capsule" AllowDrag="true" ShowToolbar="true">
458458
<TabItem Text="@Localizer["TabItem1Text"]" Icon="fa-solid fa-user">
459459
<div>@Localizer["TabItem1Content"]</div>
460-
<Counter></Counter>
461460
</TabItem>
462461
<TabItem Text="@Localizer["TabItem2Text"]" Icon="fa-solid fa-gauge-high">
463462
<div>@Localizer["TabItem2Content"]</div>
@@ -472,10 +471,14 @@ private void Navigation()
472471
</DemoBlock>
473472

474473
<DemoBlock Title="@Localizer["TabsToolbarTitle"]" Introduction="@Localizer["TabsToolbarIntro"]" Name="Toolbar">
474+
<section ignore>
475+
<div>@((MarkupString)Localizer["TabsToolbarDesc"].Value)</div>
476+
</section>
475477
<Tab IsCard="true" ShowClose="true" TabStyle="TabStyle.Chrome" ShowToolbar="true">
476478
<ChildContent>
477479
<TabItem Text="@Localizer["TabItem1Text"]" Icon="fa-solid fa-user">
478480
<div>@Localizer["TabItem1Content"]</div>
481+
<Counter></Counter>
479482
</TabItem>
480483
<TabItem Text="@Localizer["TabItem2Text"]" Icon="fa-solid fa-gauge-high">
481484
<div>@Localizer["TabItem2Content"]</div>
@@ -488,7 +491,7 @@ private void Navigation()
488491
</TabItem>
489492
</ChildContent>
490493
<ToolbarTemplate>
491-
<TabToolbarButton Icon="fa fa-home" TooltipText="Home"></TabToolbarButton>
494+
<TabToolbarButton Icon="fa fa-home fa-shake" TooltipText="Home"></TabToolbarButton>
492495
</ToolbarTemplate>
493496
</Tab>
494497
</DemoBlock>

src/BootstrapBlazor.Server/Components/Samples/Tabs.razor.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,14 @@ private AttributeItem[] GetAttributes() =>
442442
DefaultValue = " — "
443443
},
444444
new()
445+
{
446+
Name = nameof(Tab.OnToolbarRefreshCallback),
447+
Description = Localizer["AttributeOnToolbarRefreshCallback"].Value,
448+
Type = "Func<Task>",
449+
ValueList = " — ",
450+
DefaultValue = " — "
451+
},
452+
new()
445453
{
446454
Name = nameof(Tab.FullscreenToolbarButtonIcon),
447455
Description = Localizer["AttributeFullscreenToolbarButtonIcon"].Value,

src/BootstrapBlazor.Server/Locales/en-US.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,14 +2123,16 @@
21232123
"TabsCapsuleStyleIntro": "Set the capsule tab style by setting <code>TabStyle=\"TabStyle.Capsule\"</code>. Currently only supports <code>Placement=\"Placement.Top\"</code> <code>Placement=\"Placement.Bottom\"</code> mode",
21242124
"AttributeToolbarTemplate": "The template for Toolbar",
21252125
"TabsToolbarTitle": "Toolbar",
2126-
"TabsToolbarIntro": "By setting <code>ShowToolbar</code>, you can display the tab toolbar. By default, the <b>Refresh</b> and <b>Fullscreen</b> buttons are displayed. You can control whether to display them by <code>ShowRefreshToolbarButton</code> and <code>ShowFullscreenToolbarButton</code>",
2126+
"TabsToolbarIntro": "By setting <code>ShowToolbar</code>, you can display the tab toolbar. By default, the <b>Refresh</b> and <b>Fullscreen</b> buttons are displayed. You can control whether to display them by <code>ShowRefreshToolbarButton</code> and <code>ShowFullscreenToolbarButton</code>, click the <b>Refresh</b> button to trigger the <code>OnToolbarRefreshCallback</code> callback method. You can customize toolbar buttons using <code>ToolbarTemplate</code>",
21272127
"AttributeShowToolbar": "Whether to display the toolbar",
21282128
"AttributeShowRefreshToolbarButton": "Whether to display the toolbar refresh button",
21292129
"AttributeShowFullscreenToolbarButton": "Whether to display the toolbar full screen button",
21302130
"AttributeRefreshToolbarTooltipText": "Toolbar refresh button tooltip text",
21312131
"AttributeFullscreenToolbarTooltipText": "Toolbar full screen button tooltip text",
21322132
"AttributeRefreshToolbarButtonIcon": "Toolbar refresh button icon",
2133-
"AttributeFullscreenToolbarButtonIcon": "Toolbar full screen button icon"
2133+
"AttributeFullscreenToolbarButtonIcon": "Toolbar full screen button icon",
2134+
"TabsToolbarDesc": "After clicking the button, the counter value increases, and clicking the <b>Refresh</b> button on the toolbar will reset the counter.",
2135+
"AttributeOnToolbarRefreshCallback": "Click the toolbar refresh button callback method"
21342136
},
21352137
"BootstrapBlazor.Server.Components.Components.DemoTabItem": {
21362138
"Info": "Reset the title of this <code>TabItem</code> by click the button",

src/BootstrapBlazor.Server/Locales/zh-CN.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,14 +2123,16 @@
21232123
"TabsCapsuleStyleIntro": "通过设置 <code>TabStyle=\"TabStyle.Capsule\"</code> 设置标签页为胶囊样式,目前仅支持 <code>Placement=\"Placement.Top\"</code> <code>Placement=\"Placement.Bottom\"</code> 模式",
21242124
"AttributeToolbarTemplate": "Toolbar 模板",
21252125
"TabsToolbarTitle": "工具栏",
2126-
"TabsToolbarIntro": "通过设置 <code>ShowToolbar</code> 显示标签页工具栏,默认显示 <b>刷新</b> <b>全屏</b> 按钮,可以通过 <code>ShowRefreshToolbarButton</code> <code>ShowFullscreenToolbarButton</code> 控制是否显示",
2126+
"TabsToolbarIntro": "通过设置 <code>ShowToolbar</code> 显示标签页工具栏,默认显示 <b>刷新</b> <b>全屏</b> 按钮,可以通过 <code>ShowRefreshToolbarButton</code> <code>ShowFullscreenToolbarButton</code> 控制是否显示,点击 <b>刷新</b> 按钮后触发 <code>OnToolbarRefreshCallback</code> 回调方法,可以通过 <code>ToolbarTemplate</code> 自定义工具栏按钮",
21272127
"AttributeShowToolbar": "是否显示工具栏",
21282128
"AttributeShowRefreshToolbarButton": "是否显示工具栏刷新按钮",
21292129
"AttributeShowFullscreenToolbarButton": "是否显示工具栏全屏按钮",
21302130
"AttributeRefreshToolbarTooltipText": "工具栏刷新按钮提示框文字",
21312131
"AttributeFullscreenToolbarTooltipText": "工具栏全屏按钮提示框文字",
21322132
"AttributeRefreshToolbarButtonIcon": "工具栏刷新按钮图标",
2133-
"AttributeFullscreenToolbarButtonIcon": "工具栏全屏按钮图标"
2133+
"AttributeFullscreenToolbarButtonIcon": "工具栏全屏按钮图标",
2134+
"TabsToolbarDesc": "点击按钮计数器数值增加后,点击工具栏的 <b>刷新</b> 按钮计数器清零",
2135+
"AttributeOnToolbarRefreshCallback": "点击工具栏刷新按钮回调方法"
21342136
},
21352137
"BootstrapBlazor.Server.Components.Components.DemoTabItem": {
21362138
"Info": "点击下方按钮,本 <code>TabItem</code> 标题更改为当前分钟与秒",

src/BootstrapBlazor/Components/Tab/Tab.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ else
9292
<FullScreenButton TargetId="@Id"
9393
Icon="@FullscreenToolbarButtonIcon"
9494
TooltipText="@FullscreenToolbarTooltipText"
95-
TooltipPlacement="Placement.Bottom"></FullScreenButton>
95+
TooltipPlacement="Placement.Bottom" TooltipTrigger="hover"></FullScreenButton>
9696
</div>
9797
}
9898
@if (ToolbarTemplate != null)

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,12 @@ public partial class Tab : IHandlerException
338338
[Parameter]
339339
public string? RefreshToolbarTooltipText { get; set; }
340340

341+
/// <summary>
342+
/// Gets or sets the refresh toolbar button click event callback. Default is null.
343+
/// </summary>
344+
[Parameter]
345+
public Func<Task>? OnToolbarRefreshCallback { get; set; }
346+
341347
[CascadingParameter]
342348
private Layout? Layout { get; set; }
343349

@@ -934,12 +940,16 @@ public async Task DragItemCallback(int originIndex, int currentIndex)
934940

935941
private string? GetIdByTabItem(TabItem item) => ComponentIdGenerator.Generate(item);
936942

937-
private Task OnRefreshAsync()
943+
private async Task OnRefreshAsync()
938944
{
939945
// refresh the active tab item
940946
var item = TabItems.FirstOrDefault(i => i.IsActive);
941947
item.Refresh(_cache);
942-
return Task.CompletedTask;
948+
949+
if (OnToolbarRefreshCallback != null)
950+
{
951+
await OnToolbarRefreshCallback();
952+
}
943953
}
944954

945955
/// <summary>

src/BootstrapBlazor/Components/Tab/TabToolbarButton.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@namespace BootstrapBlazor.Components
22
@inherits BootstrapModuleComponentBase
33

4-
<Tooltip Title="@TooltipText" Placement="Placement.Bottom">
4+
<Tooltip Title="@TooltipText" Placement="Placement.Bottom" Trigger="hover">
55
<div @attributes="@AdditionalAttributes" class="@ClassString" @onclick="OnClick">
66
<i class="@Icon"></i>
77
</div>

test/UnitTest/Components/TabTest.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,7 @@ public void BeforeNavigatorTemplate_Ok()
10211021
[Fact]
10221022
public async Task ShowToolbar_Ok()
10231023
{
1024+
var clicked = false;
10241025
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
10251026
{
10261027
pb.AddChildContent<Tab>(pb =>
@@ -1032,6 +1033,11 @@ public async Task ShowToolbar_Ok()
10321033
pb.Add(a => a.Text, "Text1");
10331034
pb.Add(a => a.ChildContent, builder => builder.AddContent(0, "Test1"));
10341035
});
1036+
pb.Add(a => a.OnToolbarRefreshCallback, () =>
1037+
{
1038+
clicked = true;
1039+
return Task.CompletedTask;
1040+
});
10351041
});
10361042
});
10371043
cut.DoesNotContain("tabs-nav-toolbar");
@@ -1046,8 +1052,9 @@ public async Task ShowToolbar_Ok()
10461052
cut.Contains("tabs-nav-toolbar-fs");
10471053

10481054
// 点击刷新按钮
1049-
var button = cut.Find(".tabs-nav-toolbar-refresh > i");
1055+
var button = cut.Find(".tabs-nav-toolbar-refresh");
10501056
await cut.InvokeAsync(() => button.Click());
1057+
Assert.True(clicked);
10511058

10521059
tab.SetParametersAndRender(pb =>
10531060
{

0 commit comments

Comments
 (0)