Skip to content

Commit 20e7174

Browse files
authored
feat(Button): add reset OnClick logic (#7887)
* doc: 更新注释 * refactor: 增加 OnClick 重置逻辑
1 parent 39735ce commit 20e7174

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/BootstrapBlazor/Components/Button/ButtonBase.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
55

6-
using Microsoft.AspNetCore.Components.Web;
7-
86
namespace BootstrapBlazor.Components;
97

108
/// <summary>
@@ -65,7 +63,7 @@ public abstract class ButtonBase : TooltipWrapperBase
6563
/// <para lang="en">Gets or sets the OnClick event</para>
6664
/// </summary>
6765
[Parameter]
68-
public EventCallback<MouseEventArgs> OnClick { get; set; }
66+
public EventCallback OnClick { get; set; }
6967

7068
/// <summary>
7169
/// <para lang="zh">获得/设置 OnClick 事件不刷新父组件</para>
@@ -206,8 +204,7 @@ protected override void OnInitialized()
206204
}
207205

208206
/// <summary>
209-
/// <para lang="zh">OnParametersSet 方法</para>
210-
/// <para lang="en">OnParametersSet method</para>
207+
/// <inheritdoc/>
211208
/// </summary>
212209
protected override void OnParametersSet()
213210
{
@@ -223,8 +220,7 @@ protected override void OnParametersSet()
223220

224221
private bool _prevDisable;
225222
/// <summary>
226-
/// <para lang="zh">OnAfterRenderAsync 方法</para>
227-
/// <para lang="en">OnAfterRenderAsync method</para>
223+
/// <inheritdoc/>
228224
/// </summary>
229225
/// <param name="firstRender"></param>
230226
protected override async Task OnAfterRenderAsync(bool firstRender)
@@ -329,14 +325,23 @@ public virtual async Task RemoveTooltip()
329325
}
330326

331327
/// <summary>
332-
/// <para lang="zh">DisposeAsyncCore 方法</para>
333-
/// <para lang="en">DisposeAsyncCore method</para>
328+
/// <inheritdoc/>
334329
/// </summary>
335330
/// <param name="disposing"></param>
336331
protected override async ValueTask DisposeAsync(bool disposing)
337332
{
338333
if (disposing)
339334
{
335+
if (OnClick.HasDelegate)
336+
{
337+
OnClick = EventCallback.Empty;
338+
}
339+
340+
if (IsAsync && ValidateForm != null)
341+
{
342+
ValidateForm.UnregisterAsyncSubmitButton(this);
343+
}
344+
340345
await RemoveTooltip();
341346
}
342347
await base.DisposeAsync(disposing);

0 commit comments

Comments
 (0)