@@ -6302,7 +6302,46 @@ public void ShowEditButton_Ok()
63026302 {
63036303 pb . Add ( a => a . ShowEditButton , false ) ;
63046304 } ) ;
6305- cut . WaitForAssertion ( ( ) => table . DoesNotContain ( "fa-regular fa-pen-to-square" ) ) ;
6305+ table . DoesNotContain ( "fa-regular fa-pen-to-square" ) ;
6306+ }
6307+
6308+ [ Fact ]
6309+ public void DisableEditButtonCallback_Ok ( )
6310+ {
6311+ var localizer = Context . Services . GetRequiredService < IStringLocalizer < Foo > > ( ) ;
6312+ var items = Foo . GenerateFoo ( localizer , 2 ) ;
6313+ var cut = Context . RenderComponent < BootstrapBlazorRoot > ( pb =>
6314+ {
6315+ pb . AddChildContent < Table < Foo > > ( pb =>
6316+ {
6317+ pb . Add ( a => a . RenderMode , TableRenderMode . Table ) ;
6318+ pb . Add ( a => a . Items , items ) ;
6319+ pb . Add ( a => a . ShowToolbar , true ) ;
6320+ pb . Add ( a => a . TableColumns , foo => builder =>
6321+ {
6322+ builder . OpenComponent < TableColumn < Foo , string > > ( 0 ) ;
6323+ builder . AddAttribute ( 1 , "Field" , "Name" ) ;
6324+ builder . AddAttribute ( 2 , "FieldExpression" , Utility . GenerateValueExpression ( foo , "Name" , typeof ( string ) ) ) ;
6325+ builder . CloseComponent ( ) ;
6326+ } ) ;
6327+ pb . Add ( a => a . SelectedRows , [ items [ 0 ] ] ) ;
6328+ } ) ;
6329+ } ) ;
6330+
6331+ var buttons = cut . FindComponents < Button > ( ) ;
6332+ var editButton = buttons . First ( i => i . Instance . Text == "编辑" ) ;
6333+ Assert . False ( editButton . Instance . IsDisabled ) ;
6334+
6335+ // 即使选中行,编辑按钮仍然被禁用
6336+ var table = cut . FindComponent < Table < Foo > > ( ) ;
6337+ table . SetParametersAndRender ( pb =>
6338+ {
6339+ pb . Add ( a => a . DisableEditButtonCallback , items =>
6340+ {
6341+ return true ;
6342+ } ) ;
6343+ } ) ;
6344+ Assert . True ( editButton . Instance . IsDisabled ) ;
63066345 }
63076346
63086347 [ Fact ]
@@ -6337,6 +6376,44 @@ public void ShowDeleteButton_Ok()
63376376 cut . WaitForAssertion ( ( ) => cut . DoesNotContain ( "fa-solid fa-xmark" ) ) ;
63386377 }
63396378
6379+ [ Fact ]
6380+ public void DisableDeleteButtonCallback_Ok ( )
6381+ {
6382+ var localizer = Context . Services . GetRequiredService < IStringLocalizer < Foo > > ( ) ;
6383+ var items = Foo . GenerateFoo ( localizer , 2 ) ;
6384+ var cut = Context . RenderComponent < BootstrapBlazorRoot > ( pb =>
6385+ {
6386+ pb . AddChildContent < Table < Foo > > ( pb =>
6387+ {
6388+ pb . Add ( a => a . RenderMode , TableRenderMode . Table ) ;
6389+ pb . Add ( a => a . Items , items ) ;
6390+ pb . Add ( a => a . ShowToolbar , true ) ;
6391+ pb . Add ( a => a . TableColumns , foo => builder =>
6392+ {
6393+ builder . OpenComponent < TableColumn < Foo , string > > ( 0 ) ;
6394+ builder . AddAttribute ( 1 , "Field" , "Name" ) ;
6395+ builder . AddAttribute ( 2 , "FieldExpression" , Utility . GenerateValueExpression ( foo , "Name" , typeof ( string ) ) ) ;
6396+ builder . CloseComponent ( ) ;
6397+ } ) ;
6398+ pb . Add ( a => a . SelectedRows , [ items [ 0 ] ] ) ;
6399+ } ) ;
6400+ } ) ;
6401+
6402+ var deleteButton = cut . FindComponent < TableToolbarPopConfirmButton < Foo > > ( ) ;
6403+ Assert . False ( deleteButton . Instance . IsDisabled ) ;
6404+
6405+ // 即使选中行,编辑按钮仍然被禁用
6406+ var table = cut . FindComponent < Table < Foo > > ( ) ;
6407+ table . SetParametersAndRender ( pb =>
6408+ {
6409+ pb . Add ( a => a . DisableDeleteButtonCallback , items =>
6410+ {
6411+ return true ;
6412+ } ) ;
6413+ } ) ;
6414+ Assert . True ( deleteButton . Instance . IsDisabled ) ;
6415+ }
6416+
63406417 [ Fact ]
63416418 public void ShowEditButtonCallback_Ok ( )
63426419 {
0 commit comments