File tree Expand file tree Collapse file tree 4 files changed +42
-32
lines changed
src/BootstrapBlazor/Components/Button Expand file tree Collapse file tree 4 files changed +42
-32
lines changed Original file line number Diff line number Diff line change @@ -65,24 +65,4 @@ protected virtual async Task OnClickButton()
6565 /// </summary>
6666 /// <returns></returns>
6767 public ValueTask FocusAsync ( ) => ButtonElement . FocusAsync ( ) ;
68-
69- /// <summary>
70- /// 处理点击方法
71- /// </summary>
72- /// <returns></returns>
73- protected virtual async Task HandlerClick ( )
74- {
75- if ( OnClickWithoutRender != null )
76- {
77- if ( ! IsAsync )
78- {
79- IsNotRender = true ;
80- }
81- await OnClickWithoutRender ( ) ;
82- }
83- if ( OnClick . HasDelegate )
84- {
85- await OnClick . InvokeAsync ( ) ;
86- }
87- }
8868}
Original file line number Diff line number Diff line change @@ -231,6 +231,26 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
231231 }
232232 }
233233
234+ /// <summary>
235+ /// 处理点击方法
236+ /// </summary>
237+ /// <returns></returns>
238+ protected virtual async Task HandlerClick ( )
239+ {
240+ if ( OnClickWithoutRender != null )
241+ {
242+ if ( ! IsAsync )
243+ {
244+ IsNotRender = true ;
245+ }
246+ await OnClickWithoutRender ( ) ;
247+ }
248+ if ( OnClick . HasDelegate )
249+ {
250+ await OnClick . InvokeAsync ( ) ;
251+ }
252+ }
253+
234254 /// <summary>
235255 /// 设置按钮是否可用状态
236256 /// </summary>
Original file line number Diff line number Diff line change 55
66using Microsoft . AspNetCore . Components . Rendering ;
77using Microsoft . AspNetCore . Components . Web ;
8- using System ;
98
109namespace BootstrapBlazor . Components ;
1110
1211/// <summary>
1312/// LinkButton 组件
1413/// </summary>
15- public sealed class LinkButton : ButtonBase
14+ public class LinkButton : ButtonBase
1615{
1716 /// <summary>
1817 /// 获得/设置 Url 默认为 #
@@ -120,14 +119,19 @@ private RenderFragment AddImage() => builder =>
120119
121120 private async Task OnClickButton ( )
122121 {
123- if ( OnClickWithoutRender != null )
122+ if ( IsAsync )
124123 {
125- await OnClickWithoutRender ( ) ;
124+ IsAsyncLoading = true ;
125+ IsDisabled = true ;
126126 }
127127
128- if ( OnClick . HasDelegate )
128+ await HandlerClick ( ) ;
129+
130+ // 恢复按钮
131+ if ( IsAsync )
129132 {
130- await OnClick . InvokeAsync ( ) ;
133+ IsDisabled = IsKeepDisabled ;
134+ IsAsyncLoading = false ;
131135 }
132136 }
133137}
Original file line number Diff line number Diff line change @@ -77,16 +77,22 @@ public void ChildContent_Ok()
7777 }
7878
7979 [ Fact ]
80- public void OnClick_Ok ( )
80+ public async Task OnClick_Ok ( )
8181 {
8282 var click = false ;
83- var cut = Context . RenderComponent < LinkButton > ( builder => builder . Add ( s => s . OnClick , ( ) => click = true ) ) ;
84-
85- cut . InvokeAsync ( ( ) =>
83+ var cut = Context . RenderComponent < LinkButton > ( pb =>
8684 {
87- cut . Find ( "a" ) . Click ( ) ;
88- Assert . True ( click ) ;
85+ pb . Add ( a => a . IsAsync , true ) ;
86+ pb . Add ( s => s . OnClick , async ( ) =>
87+ {
88+ click = true ;
89+ await Task . Yield ( ) ;
90+ } ) ;
8991 } ) ;
92+
93+ var link = cut . Find ( "a" ) ;
94+ await cut . InvokeAsync ( ( ) => link . Click ( ) ) ;
95+ Assert . True ( click ) ;
9096 }
9197
9298 [ Fact ]
You can’t perform that action at this time.
0 commit comments