Skip to content

Commit 5e87e73

Browse files
authored
fix(Popover): OnBeforeClick does not take effect (#2879)
* fix: 修复 OnBeforeClick 二次点击不生效问题 * chore: bump version 8.2.0
1 parent 1c1a912 commit 5e87e73

File tree

5 files changed

+20
-6
lines changed

5 files changed

+20
-6
lines changed

src/BootstrapBlazor/BootstrapBlazor.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>8.1.10-beta04</Version>
4+
<Version>8.2.0</Version>
55
</PropertyGroup>
66

77
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">

src/BootstrapBlazor/Components/Button/PopConfirmButton.razor

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ else
1515
@code {
1616
RenderFragment RenderComponent =>
1717
@<DynamicElement TagName="@TagName" OnClick="Show" id="@Id"
18-
class="@ClassString" role="dialog" tabindex="@Tab"
18+
class="@ClassString" role="dialog" tabindex="@Tab" data-bb-confirm="@ConfirmString"
1919
data-bs-custom-class="@CustomClassString" data-bs-trigger="@TriggerString" data-bs-placement="@PlacementString">
2020
@if (!string.IsNullOrEmpty(ButtonIcon))
2121
{

src/BootstrapBlazor/Components/Button/PopConfirmButton.razor.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,20 @@ protected override void OnParametersSet()
6666
/// <returns></returns>
6767
public override Task RemoveTooltip() => Task.CompletedTask;
6868

69+
private string? ConfirmString => OnBeforeClick != null ? "true" : null;
70+
6971
/// <summary>
7072
/// 显示确认弹窗方法
7173
/// </summary>
7274
private async Task Show()
7375
{
7476
// 回调消费者逻辑 判断是否需要弹出确认框
75-
if (await OnBeforeClick())
77+
var show = true;
78+
if (OnBeforeClick != null)
79+
{
80+
show = await OnBeforeClick();
81+
}
82+
if (show)
7683
{
7784
await InvokeVoidAsync("showConfirm", Id);
7885
}

src/BootstrapBlazor/Components/Button/PopConfirmButton.razor.js

+9
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ export function init(id) {
4444
for (let i = 1; i < len; i++) {
4545
confirm.container.appendChild(children[1])
4646
}
47+
48+
const handler = setTimeout(() => {
49+
clearTimeout(handler);
50+
const hasConfirm = el.hasAttribute('data-bb-confirm');
51+
if (hasConfirm) {
52+
confirm.popover.dispose();
53+
delete confirm.popover;
54+
}
55+
}, 50);
4756
}
4857

4958
EventHandler.on(el, 'show.bs.popover', confirm.show)

src/BootstrapBlazor/Components/Button/PopConfirmButtonBase.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,9 @@ public abstract class PopConfirmButtonBase : ButtonBase
6666
public Func<Task>? OnClose { get; set; }
6767

6868
/// <summary>
69-
/// 获得/设置 点击确认弹窗前回调方法 返回真时弹出弹窗 返回假时不弹出
69+
/// 获得/设置 点击确认弹窗前回调方法 返回真时弹出弹窗 返回假时不弹出 默认 null
7070
/// </summary>
7171
[Parameter]
72-
[NotNull]
7372
public Func<Task<bool>>? OnBeforeClick { get; set; }
7473

7574
/// <summary>
@@ -136,6 +135,5 @@ protected override void OnParametersSet()
136135

137136
OnClose ??= () => Task.CompletedTask;
138137
OnConfirm ??= () => Task.CompletedTask;
139-
OnBeforeClick ??= () => Task.FromResult(true);
140138
}
141139
}

0 commit comments

Comments
 (0)