!3635 feat(#I66NP7): add OnCloseTabItemAsync parameter on Tab component

* chore: bump version 7.1.7
* test: 增加单元测试
* feat: 增加 OnCloseTabItemAsync 回调方法
This commit is contained in:
Argo 2022-12-19 05:37:19 +00:00
parent d08c89c4f3
commit fd7fbbb078
3 changed files with 22 additions and 5 deletions

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<Version>7.1.7-beta01</Version>
<Version>7.1.7</Version>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">

View File

@ -92,6 +92,12 @@ public partial class Tab : IHandlerException, IDisposable
[Parameter]
public bool ShowClose { get; set; }
/// <summary>
/// 关闭标签页回调方法
/// </summary>
[Parameter]
public Func<TabItem, Task>? OnCloseTabItemAsync { get; set; }
/// <summary>
/// 获得/设置 是否显示扩展功能按钮 默认为 false 不显示
/// </summary>
@ -379,14 +385,13 @@ public partial class Tab : IHandlerException, IDisposable
/// <summary>
/// 关闭当前标签页方法
/// </summary>
public Task CloseCurrentTab()
public async Task CloseCurrentTab()
{
var tab = _items.FirstOrDefault(t => t.IsActive);
if (tab != null && tab.Closable)
{
RemoveTab(tab);
await RemoveTab(tab);
}
return Task.CompletedTask;
}
private void OnClickCloseAllTabs() => _items.RemoveAll(t => t.Closable);
@ -531,10 +536,14 @@ public partial class Tab : IHandlerException, IDisposable
/// 移除 TabItem 方法
/// </summary>
/// <param name="item"></param>
public void RemoveTab(TabItem item)
public async Task RemoveTab(TabItem item)
{
var index = _items.IndexOf(item);
_items.Remove(item);
if (OnCloseTabItemAsync != null)
{
await OnCloseTabItemAsync(item);
}
var activeItem = _items.FirstOrDefault(i => i.IsActive);
if (activeItem == null)
{

View File

@ -77,11 +77,17 @@ public class TabTest : TabTestBase
public void ClickTab_Ok()
{
var clicked = false;
TabItem? closedItem = null;
var cut = Context.RenderComponent<Tab>(pb =>
{
pb.Add(a => a.ShowExtendButtons, true);
pb.Add(a => a.Placement, Placement.Bottom);
pb.Add(a => a.ShowClose, true);
pb.Add(a => a.OnCloseTabItemAsync, item =>
{
closedItem = item;
return Task.CompletedTask;
});
pb.Add(a => a.OnClickTab, item =>
{
clicked = true;
@ -121,8 +127,10 @@ public class TabTest : TabTestBase
Assert.Equal("Tab2-Content", cut.Find(".tabs-body .d-none").InnerHtml);
// Close
Assert.Null(closedItem);
button = cut.Find(".tabs-item-close");
button.Click();
Assert.NotNull(closedItem);
}
[Fact]