Skip to content

Commit

Permalink
fix(Popover): OnBeforeClick does not take effect (#2879)
Browse files Browse the repository at this point in the history
* fix: 修复 OnBeforeClick 二次点击不生效问题

* chore: bump version 8.2.0
  • Loading branch information
ArgoZhang authored Jan 31, 2024
1 parent 1c1a912 commit 5e87e73
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>8.1.10-beta04</Version>
<Version>8.2.0</Version>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ else
@code {
RenderFragment RenderComponent =>
@<DynamicElement TagName="@TagName" OnClick="Show" id="@Id"
class="@ClassString" role="dialog" tabindex="@Tab"
class="@ClassString" role="dialog" tabindex="@Tab" data-bb-confirm="@ConfirmString"
data-bs-custom-class="@CustomClassString" data-bs-trigger="@TriggerString" data-bs-placement="@PlacementString">
@if (!string.IsNullOrEmpty(ButtonIcon))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,20 @@ protected override void OnParametersSet()
/// <returns></returns>
public override Task RemoveTooltip() => Task.CompletedTask;

private string? ConfirmString => OnBeforeClick != null ? "true" : null;

/// <summary>
/// 显示确认弹窗方法
/// </summary>
private async Task Show()
{
// 回调消费者逻辑 判断是否需要弹出确认框
if (await OnBeforeClick())
var show = true;
if (OnBeforeClick != null)
{
show = await OnBeforeClick();
}
if (show)
{
await InvokeVoidAsync("showConfirm", Id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ public abstract class PopConfirmButtonBase : ButtonBase
public Func<Task>? OnClose { get; set; }

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

/// <summary>
Expand Down Expand Up @@ -136,6 +135,5 @@ protected override void OnParametersSet()

OnClose ??= () => Task.CompletedTask;
OnConfirm ??= () => Task.CompletedTask;
OnBeforeClick ??= () => Task.FromResult(true);
}
}

0 comments on commit 5e87e73

Please sign in to comment.