Skip to content

Commit b9e9111

Browse files
authored
fix(Table): should show the Toast when not set BootstrapBlazorOption ToastDelay (#5810)
* wip: 临时提交 * test: 更新单元测试 * refactor: 重构代码 * refactor: 移除参数 * refactor: 重构 ToastDelay 取值逻辑 * test: 更新单元测试
1 parent bb45f76 commit b9e9111

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

src/BootstrapBlazor/Components/Message/MessageService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public async Task Show(MessageOption option, Message? message = null)
2222
{
2323
if (!option.ForceDelay)
2424
{
25-
if (Options.MessageDelay != 0)
25+
if (Options.MessageDelay > 0)
2626
{
2727
option.Delay = Options.MessageDelay;
2828
}

src/BootstrapBlazor/Components/SweetAlert/SwalService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class SwalService(IOptionsMonitor<BootstrapBlazorOptions> options) : Boot
1717
/// <param name="swal">指定弹窗组件 默认为 null 使用 <see cref="BootstrapBlazorRoot"/> 组件内置弹窗组件</param>
1818
public async Task Show(SwalOption option, SweetAlert? swal = null)
1919
{
20-
if (!option.ForceDelay && options.CurrentValue.SwalDelay != 0)
20+
if (!option.ForceDelay && options.CurrentValue.SwalDelay > 0)
2121
{
2222
option.Delay = options.CurrentValue.SwalDelay;
2323
}

src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,11 +1153,18 @@ private async Task ExecuteExportAsync(Func<Task<bool>> callback)
11531153
}
11541154
}
11551155

1156-
private ToastOption GetToastOption(string title) => new()
1156+
private ToastOption GetToastOption(string title)
11571157
{
1158-
Title = title,
1159-
Delay = Options.CurrentValue.ToastDelay
1160-
};
1158+
var option = new ToastOption()
1159+
{
1160+
Title = title,
1161+
};
1162+
if (Options.CurrentValue.ToastDelay > 0)
1163+
{
1164+
option.Delay = Options.CurrentValue.ToastDelay;
1165+
}
1166+
return option;
1167+
}
11611168

11621169
private Task ExportAsync() => ExecuteExportAsync(() => OnExportAsync != null
11631170
? OnExportAsync(new TableExportDataContext<TItem>(TableExportType.Unknown, Rows, GetVisibleColumns(), BuildQueryPageOptions()))

test/UnitTest/Components/TableDialogTest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using AngleSharp.Dom;
77
using Microsoft.AspNetCore.Components.Web;
88
using Microsoft.Extensions.Localization;
9+
using Microsoft.Extensions.Options;
910
using System.Reflection;
1011

1112
namespace UnitTest.Components;
@@ -15,6 +16,8 @@ public class TableDialogTest : TableDialogTestBase
1516
[Fact]
1617
public async Task EditAsync_Ok()
1718
{
19+
var options = Context.Services.GetRequiredService<IOptionsMonitor<BootstrapBlazorOptions>>();
20+
options.CurrentValue.ToastDelay = 0;
1821
var localizer = Context.Services.GetRequiredService<IStringLocalizer<Foo>>();
1922
var items = Foo.GenerateFoo(localizer, 2);
2023
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>

0 commit comments

Comments
 (0)