Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>9.5.11-beta03</Version>
<Version>9.5.11-beta04</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
11 changes: 9 additions & 2 deletions src/BootstrapBlazor/Components/Button/PopConfirmButton.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ private async Task OnClickConfirm()
IsDisabled = true;
IsAsyncLoading = true;
StateHasChanged();
await Task.Run(() => InvokeAsync(OnConfirm));

if (OnConfirm != null)
{
await Task.Run(() => InvokeAsync(OnConfirm));
}

if (ButtonType == ButtonType.Submit)
{
Expand All @@ -112,7 +116,10 @@ private async Task OnClickConfirm()
}
else
{
await OnConfirm();
if (OnConfirm != null)
{
await OnConfirm();
}
if (ButtonType == ButtonType.Submit)
{
await TrySubmit();
Expand Down
25 changes: 21 additions & 4 deletions src/BootstrapBlazor/Components/Button/PopConfirmButton.razor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const config = {
popoverSelector: '.popover-confirm.show'
}

export function init(id) {
export function init(id, invoke, closeCallback = null) {
const el = document.getElementById(id)
if (el == null) {
return
Expand All @@ -18,7 +18,9 @@ export function init(id) {

const confirm = {
el,
container: el.querySelector('[data-bb-toggle="confirm"]')
container: el.querySelector('[data-bb-toggle="confirm"]'),
invoke,
closeCallback
}
Data.set(id, confirm)

Expand Down Expand Up @@ -79,7 +81,16 @@ export function init(id) {
if (element) {
const popover = bootstrap.Popover.getInstance(element);
if (popover) {
popover.hide()
popover.hide();

const id = element.getAttribute('id');
if (id) {
const com = Data.get(id);
const { invoke, closeCallback } = com;
if (invoke && closeCallback) {
invoke.invokeMethodAsync(closeCallback);
}
}
}
}
})
Expand Down Expand Up @@ -135,11 +146,17 @@ export function dispose(id) {
const confirm = Data.get(id)
Data.remove(id)

const { popover } = confirm ?? {};
const { popover, el } = confirm ?? {};
if (popover) {
popover.dispose();
}

if (el) {
EventHandler.off(el, 'show.bs.popover')
EventHandler.off(el, 'inserted.bs.popover')
EventHandler.off(el, 'hide.bs.popover')
}

const { PopConfirmButton } = window.BootstrapBlazor;
PopConfirmButton.dispose(id, () => {
EventHandler.off(document, 'click', confirm.closeConfirm)
Expand Down
26 changes: 20 additions & 6 deletions src/BootstrapBlazor/Components/Button/PopConfirmButtonBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/// <summary>
/// 确认弹窗按钮组件
/// </summary>
[BootstrapModuleAutoLoader("Button/PopConfirmButton.razor.js")]
[BootstrapModuleAutoLoader("Button/PopConfirmButton.razor.js", JSObjectReference = true)]
public abstract class PopConfirmButtonBase : ButtonBase
{
/// <summary>
Expand Down Expand Up @@ -57,7 +57,6 @@
/// 获得/设置 点击确认时回调方法
/// </summary>
[Parameter]
[NotNull]
public Func<Task>? OnConfirm { get; set; }

/// <summary>
Expand All @@ -70,7 +69,6 @@
/// 获得/设置 点击关闭时回调方法
/// </summary>
[Parameter]
[NotNull]
public Func<Task>? OnClose { get; set; }

/// <summary>
Expand Down Expand Up @@ -160,12 +158,28 @@
ConfirmIcon ??= IconTheme.GetIconByKey(ComponentIcons.PopConfirmButtonConfirmIcon);
Trigger ??= "click";

OnClose ??= () => Task.CompletedTask;
OnConfirm ??= () => Task.CompletedTask;

if (Placement != Placement.Top && Placement != Placement.Right && Placement != Placement.Bottom && Placement != Placement.Left)
{
Placement = Placement.Auto;
}
}

/// <summary>
/// <inheritdoc/>
/// </summary>
/// <returns></returns>
protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Interop, OnClose == null ? null : nameof(TriggerCloseCallback));

/// <summary>
/// Trigger OnClose event callback.
/// </summary>
/// <returns></returns>
[JSInvokable]
public async Task TriggerCloseCallback()
{

Check warning on line 179 in src/BootstrapBlazor/Components/Button/PopConfirmButtonBase.cs

View check run for this annotation

Codecov / codecov/patch

src/BootstrapBlazor/Components/Button/PopConfirmButtonBase.cs#L179

Added line #L179 was not covered by tests
if (OnClose != null)
{
await OnClose();
}
}

Check warning on line 184 in src/BootstrapBlazor/Components/Button/PopConfirmButtonBase.cs

View check run for this annotation

Codecov / codecov/patch

src/BootstrapBlazor/Components/Button/PopConfirmButtonBase.cs#L181-L184

Added lines #L181 - L184 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ await OnClickButton(new TableCellButtonArgs()

private async Task OnClickConfirm(TableCellPopConfirmButton b)
{
await b.OnConfirm();
if (b.OnConfirm != null)
{
await b.OnConfirm();
}

if (OnClickButton != null)
{
Expand Down
5 changes: 4 additions & 1 deletion src/BootstrapBlazor/Components/Table/TableToolbar.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@
await button.OnClick.InvokeAsync();
}

await button.OnConfirm();
if (button.OnConfirm != null)
{
await button.OnConfirm();
}

Check warning on line 97 in src/BootstrapBlazor/Components/Table/TableToolbar.razor.cs

View check run for this annotation

Codecov / codecov/patch

src/BootstrapBlazor/Components/Table/TableToolbar.razor.cs#L95-L97

Added lines #L95 - L97 were not covered by tests

// 传递当前选中行给回调委托方法
if (button.OnConfirmCallback != null)
Expand Down
Loading