Skip to content

Commit ccfb30f

Browse files
authored
fix(Message): should clear when use same option (dotnetcore#6513)
* doc: 更新示例 * fix: 防止多次添加相同 Id * doc: 更新示例 * refactor: 增加取消动画逻辑 * refactor: 更新变量名称 * chore: 增加 null 赋值
1 parent a296a6d commit ccfb30f

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ private async Task ShowAsyncMessage()
3333
_option.IsAutoHide = false;
3434
_option.Delay = 3000;
3535
_option.Content = Localizer["MessagesAsyncDemoStep1Text"];
36-
_option.Color = Color.Info;
36+
_option.Color = Color.Primary;
3737
await MessageService.Show(_option);
3838

3939
await Task.Delay(3000);
4040
_option.Content = Localizer["MessagesAsyncDemoStep2Text"];
41-
_option.IsAutoHide = true;
4241
_option.Color = Color.Info;
4342
await MessageService.Show(_option);
4443

4544
await Task.Delay(2000);
45+
_option.IsAutoHide = true;
4646
_option.Content = Localizer["MessagesAsyncDemoStep3Text"];
4747
_option.Color = Color.Success;
4848

src/BootstrapBlazor/Components/Message/Message.razor.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,18 @@ export function show(id, msgId) {
1414
return
1515
}
1616

17-
const msgItem = { el, animationId: null }
18-
msg.items.push(msgItem)
19-
const autoHide = el.getAttribute('data-bb-autohide') === 'true';
17+
let msgItem = msg.items.find(i => i.el.id === msgId)
18+
if (msgItem === void 0) {
19+
msgItem = { el, animationId: null }
20+
msg.items.push(msgItem)
21+
}
2022

23+
if (msgItem.animationId) {
24+
cancelAnimationFrame(msgItem.animationId);
25+
}
26+
27+
const autoHide = el.getAttribute('data-bb-autohide') === 'true';
2128
if (autoHide) {
22-
// auto close
2329
const delay = parseInt(el.getAttribute('data-bb-delay'));
2430
let start = void 0
2531
const autoCloseAnimation = ts => {
@@ -45,10 +51,8 @@ export function show(id, msgId) {
4551
const hideHandler = setTimeout(function () {
4652
clearTimeout(hideHandler);
4753

48-
// remove Id
4954
msg.items.pop();
5055
if (msg.items.length === 0) {
51-
// call server method prepare remove dom
5256
msg.invoke.invokeMethodAsync(msg.callback);
5357
}
5458
}, 500);
@@ -58,9 +62,8 @@ export function show(id, msgId) {
5862
e.preventDefault();
5963
e.stopPropagation();
6064

61-
// trigger on-dismiss event callback
6265
const alert = e.delegateTarget.closest('.alert');
63-
if(alert) {
66+
if (alert) {
6467
const alertId = alert.getAttribute('id');
6568
msg.invoke.invokeMethodAsync('Dismiss', alertId);
6669
}
@@ -74,6 +77,7 @@ export function dispose(id) {
7477
msg.items.forEach(item => {
7578
if (item.animationId) {
7679
cancelAnimationFrame(item.animationId);
80+
item.animationId = null;
7781
}
7882
});
7983
}

0 commit comments

Comments
 (0)