From 5e87e739f520eb27e9f8eef5f14cec8a44bf8b3c Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 31 Jan 2024 21:14:48 +0800 Subject: [PATCH] fix(Popover): OnBeforeClick does not take effect (#2879) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 修复 OnBeforeClick 二次点击不生效问题 * chore: bump version 8.2.0 --- src/BootstrapBlazor/BootstrapBlazor.csproj | 2 +- .../Components/Button/PopConfirmButton.razor | 2 +- .../Components/Button/PopConfirmButton.razor.cs | 9 ++++++++- .../Components/Button/PopConfirmButton.razor.js | 9 +++++++++ .../Components/Button/PopConfirmButtonBase.cs | 4 +--- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index 663939d6afc..14fc8dbdc41 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@ - 8.1.10-beta04 + 8.2.0 diff --git a/src/BootstrapBlazor/Components/Button/PopConfirmButton.razor b/src/BootstrapBlazor/Components/Button/PopConfirmButton.razor index 83ba05dc4b1..75a54c1cc53 100644 --- a/src/BootstrapBlazor/Components/Button/PopConfirmButton.razor +++ b/src/BootstrapBlazor/Components/Button/PopConfirmButton.razor @@ -15,7 +15,7 @@ else @code { RenderFragment RenderComponent => @ @if (!string.IsNullOrEmpty(ButtonIcon)) { diff --git a/src/BootstrapBlazor/Components/Button/PopConfirmButton.razor.cs b/src/BootstrapBlazor/Components/Button/PopConfirmButton.razor.cs index 0971e1a38b3..1dd2abf4704 100644 --- a/src/BootstrapBlazor/Components/Button/PopConfirmButton.razor.cs +++ b/src/BootstrapBlazor/Components/Button/PopConfirmButton.razor.cs @@ -66,13 +66,20 @@ protected override void OnParametersSet() /// public override Task RemoveTooltip() => Task.CompletedTask; + private string? ConfirmString => OnBeforeClick != null ? "true" : null; + /// /// 显示确认弹窗方法 /// private async Task Show() { // 回调消费者逻辑 判断是否需要弹出确认框 - if (await OnBeforeClick()) + var show = true; + if (OnBeforeClick != null) + { + show = await OnBeforeClick(); + } + if (show) { await InvokeVoidAsync("showConfirm", Id); } diff --git a/src/BootstrapBlazor/Components/Button/PopConfirmButton.razor.js b/src/BootstrapBlazor/Components/Button/PopConfirmButton.razor.js index 032d467a16d..cea9cb24c97 100644 --- a/src/BootstrapBlazor/Components/Button/PopConfirmButton.razor.js +++ b/src/BootstrapBlazor/Components/Button/PopConfirmButton.razor.js @@ -44,6 +44,15 @@ export function init(id) { for (let i = 1; i < len; i++) { confirm.container.appendChild(children[1]) } + + const handler = setTimeout(() => { + clearTimeout(handler); + const hasConfirm = el.hasAttribute('data-bb-confirm'); + if (hasConfirm) { + confirm.popover.dispose(); + delete confirm.popover; + } + }, 50); } EventHandler.on(el, 'show.bs.popover', confirm.show) diff --git a/src/BootstrapBlazor/Components/Button/PopConfirmButtonBase.cs b/src/BootstrapBlazor/Components/Button/PopConfirmButtonBase.cs index 3a04e969040..ada1bec3359 100644 --- a/src/BootstrapBlazor/Components/Button/PopConfirmButtonBase.cs +++ b/src/BootstrapBlazor/Components/Button/PopConfirmButtonBase.cs @@ -66,10 +66,9 @@ public abstract class PopConfirmButtonBase : ButtonBase public Func? OnClose { get; set; } /// - /// 获得/设置 点击确认弹窗前回调方法 返回真时弹出弹窗 返回假时不弹出 + /// 获得/设置 点击确认弹窗前回调方法 返回真时弹出弹窗 返回假时不弹出 默认 null /// [Parameter] - [NotNull] public Func>? OnBeforeClick { get; set; } /// @@ -136,6 +135,5 @@ protected override void OnParametersSet() OnClose ??= () => Task.CompletedTask; OnConfirm ??= () => Task.CompletedTask; - OnBeforeClick ??= () => Task.FromResult(true); } }