diff --git a/src/BootstrapBlazor/Components/Message/Message.razor b/src/BootstrapBlazor/Components/Message/Message.razor
index 03aabd69abcd75ad109f840cececba5d43622922..56436b567f89762afd2a3750dae4efe957b89864 100644
--- a/src/BootstrapBlazor/Components/Message/Message.razor
+++ b/src/BootstrapBlazor/Components/Message/Message.razor
@@ -5,7 +5,7 @@
@foreach (var item in GetMessages())
{
-
+
}
diff --git a/src/BootstrapBlazor/Components/Message/Message.razor.cs b/src/BootstrapBlazor/Components/Message/Message.razor.cs
index 7ec1fea1261044ced527f019cf3dee9f1516a0c9..868bd6db747c8ff64d3bbedb27b829cfb05365ab 100644
--- a/src/BootstrapBlazor/Components/Message/Message.razor.cs
+++ b/src/BootstrapBlazor/Components/Message/Message.razor.cs
@@ -87,6 +87,14 @@ public partial class Message : IDisposable
await InvokeAsync(StateHasChanged);
}
+ private static async Task OnDismiss(MessageOption option)
+ {
+ if (option.OnDismiss != null)
+ {
+ await option.OnDismiss();
+ }
+ }
+
private List GetMessages()
{
if (Placement != Placement.Top)
diff --git a/src/BootstrapBlazor/Components/Message/MessageOption.cs b/src/BootstrapBlazor/Components/Message/MessageOption.cs
index bf8bf1650f6d2427e9d4a6dfcbcbd1c023071379..a1d50a65727054882e34c4e3af192bc6c0ab5953 100644
--- a/src/BootstrapBlazor/Components/Message/MessageOption.cs
+++ b/src/BootstrapBlazor/Components/Message/MessageOption.cs
@@ -10,22 +10,27 @@ namespace BootstrapBlazor.Components;
public class MessageOption : PopupOptionBase
{
///
- /// 获得/设置 颜色
+ /// 获得/设置 颜色 默认 Primary
///
public Color Color { get; set; } = Color.Primary;
///
- /// 获得/设置 是否显示关闭按钮
+ /// 获得/设置 是否显示关闭按钮 默认 false
///
public bool ShowDismiss { get; set; }
///
- /// 获得/设置 显示图标
+ /// 获得/设置 显示图标 默认 null
///
public string? Icon { get; set; }
///
- /// 获得/设置 是否显示左侧 Bar
+ /// 获得/设置 是否显示左侧 Bar 默认 false
///
public bool ShowBar { get; set; }
+
+ ///
+ /// 获得/设置 关闭当前 MessageItem 回调委托 默认 null
+ ///
+ public Func? OnDismiss { get; set; }
}
diff --git a/src/BootstrapBlazor/Components/Message/MessageService.cs b/src/BootstrapBlazor/Components/Message/MessageService.cs
index 342b316775737ad33b82faf4cbc47c619f47cf4f..47b98ccdf235b9d55057be1dadbac589e510faaf 100644
--- a/src/BootstrapBlazor/Components/Message/MessageService.cs
+++ b/src/BootstrapBlazor/Components/Message/MessageService.cs
@@ -31,11 +31,13 @@ public class MessageService : BootstrapServiceBase, IDisposable
/// 指定弹窗组件 默认为 null 使用 组件内置弹窗组件
public async Task Show(MessageOption option, Message? message = null)
{
- if (!option.ForceDelay && _option.MessageDelay != 0)
+ if (!option.ForceDelay)
{
- option.Delay = _option.MessageDelay;
+ if (_option.MessageDelay != 0)
+ {
+ option.Delay = _option.MessageDelay;
+ }
}
-
await Invoke(option, message);
}
diff --git a/test/UnitTest/Components/MessageTest.cs b/test/UnitTest/Components/MessageTest.cs
new file mode 100644
index 0000000000000000000000000000000000000000..c7aaea04f97bb1b413618be023af04f5cda8529b
--- /dev/null
+++ b/test/UnitTest/Components/MessageTest.cs
@@ -0,0 +1,63 @@
+// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+// Website: https://www.blazor.zone or https://argozhang.github.io/
+
+using Microsoft.Extensions.DependencyInjection;
+
+namespace UnitTest.Components;
+
+public class MessageTest : BootstrapBlazorTestBase
+{
+ [Fact]
+ public async Task Message_Ok()
+ {
+ var dismiss = false;
+ var service = Context.Services.GetRequiredService();
+ var cut = Context.RenderComponent(pb =>
+ {
+ pb.AddChildContent