@@ -807,6 +807,94 @@ describe('MatCheckbox', () => {
807
807
} ) ;
808
808
} ) ;
809
809
810
+ describe ( 'with provided aria-expanded' , ( ) => {
811
+ let checkboxDebugElement : DebugElement ;
812
+ let checkboxNativeElement : HTMLElement ;
813
+ let inputElement : HTMLInputElement ;
814
+
815
+ it ( 'should use the provided postive aria-expanded' , ( ) => {
816
+ fixture = createComponent ( CheckboxWithPositiveAriaExpanded ) ;
817
+ checkboxDebugElement = fixture . debugElement . query ( By . directive ( MatCheckbox ) ) ! ;
818
+ checkboxNativeElement = checkboxDebugElement . nativeElement ;
819
+ inputElement = < HTMLInputElement > checkboxNativeElement . querySelector ( 'input' ) ;
820
+
821
+ fixture . detectChanges ( ) ;
822
+ expect ( inputElement . getAttribute ( 'aria-expanded' ) ) . toBe ( 'true' ) ;
823
+ } ) ;
824
+
825
+ it ( 'should use the provided negative aria-expanded' , ( ) => {
826
+ fixture = createComponent ( CheckboxWithNegativeAriaExpanded ) ;
827
+ checkboxDebugElement = fixture . debugElement . query ( By . directive ( MatCheckbox ) ) ! ;
828
+ checkboxNativeElement = checkboxDebugElement . nativeElement ;
829
+ inputElement = < HTMLInputElement > checkboxNativeElement . querySelector ( 'input' ) ;
830
+
831
+ fixture . detectChanges ( ) ;
832
+ expect ( inputElement . getAttribute ( 'aria-expanded' ) ) . toBe ( 'false' ) ;
833
+ } ) ;
834
+
835
+ it ( 'should not assign aria-expanded if none is provided' , ( ) => {
836
+ fixture = createComponent ( SingleCheckbox ) ;
837
+ checkboxDebugElement = fixture . debugElement . query ( By . directive ( MatCheckbox ) ) ! ;
838
+ checkboxNativeElement = checkboxDebugElement . nativeElement ;
839
+ inputElement = < HTMLInputElement > checkboxNativeElement . querySelector ( 'input' ) ;
840
+
841
+ fixture . detectChanges ( ) ;
842
+ expect ( inputElement . getAttribute ( 'aria-expanded' ) ) . toBe ( null ) ;
843
+ } ) ;
844
+ } ) ;
845
+
846
+ describe ( 'with provided aria-controls' , ( ) => {
847
+ let checkboxDebugElement : DebugElement ;
848
+ let checkboxNativeElement : HTMLElement ;
849
+ let inputElement : HTMLInputElement ;
850
+
851
+ it ( 'should use the provided aria-controls' , ( ) => {
852
+ fixture = createComponent ( CheckboxWithAriaControls ) ;
853
+ checkboxDebugElement = fixture . debugElement . query ( By . directive ( MatCheckbox ) ) ! ;
854
+ checkboxNativeElement = checkboxDebugElement . nativeElement ;
855
+ inputElement = < HTMLInputElement > checkboxNativeElement . querySelector ( 'input' ) ;
856
+
857
+ fixture . detectChanges ( ) ;
858
+ expect ( inputElement . getAttribute ( 'aria-controls' ) ) . toBe ( 'some-id' ) ;
859
+ } ) ;
860
+
861
+ it ( 'should not assign aria-controls if none is provided' , ( ) => {
862
+ fixture = createComponent ( SingleCheckbox ) ;
863
+ checkboxDebugElement = fixture . debugElement . query ( By . directive ( MatCheckbox ) ) ! ;
864
+ checkboxNativeElement = checkboxDebugElement . nativeElement ;
865
+ inputElement = < HTMLInputElement > checkboxNativeElement . querySelector ( 'input' ) ;
866
+
867
+ fixture . detectChanges ( ) ;
868
+ expect ( inputElement . getAttribute ( 'aria-controls' ) ) . toBe ( null ) ;
869
+ } ) ;
870
+ } ) ;
871
+
872
+ describe ( 'with provided aria-owns' , ( ) => {
873
+ let checkboxDebugElement : DebugElement ;
874
+ let checkboxNativeElement : HTMLElement ;
875
+ let inputElement : HTMLInputElement ;
876
+
877
+ it ( 'should use the provided aria-owns' , ( ) => {
878
+ fixture = createComponent ( CheckboxWithAriaOwns ) ;
879
+ checkboxDebugElement = fixture . debugElement . query ( By . directive ( MatCheckbox ) ) ! ;
880
+ checkboxNativeElement = checkboxDebugElement . nativeElement ;
881
+ inputElement = < HTMLInputElement > checkboxNativeElement . querySelector ( 'input' ) ;
882
+
883
+ fixture . detectChanges ( ) ;
884
+ expect ( inputElement . getAttribute ( 'aria-owns' ) ) . toBe ( 'some-id' ) ;
885
+ } ) ;
886
+
887
+ it ( 'should not assign aria-owns if none is provided' , ( ) => {
888
+ fixture = createComponent ( SingleCheckbox ) ;
889
+ checkboxDebugElement = fixture . debugElement . query ( By . directive ( MatCheckbox ) ) ! ;
890
+ checkboxNativeElement = checkboxDebugElement . nativeElement ;
891
+ inputElement = < HTMLInputElement > checkboxNativeElement . querySelector ( 'input' ) ;
892
+
893
+ fixture . detectChanges ( ) ;
894
+ expect ( inputElement . getAttribute ( 'aria-owns' ) ) . toBe ( null ) ;
895
+ } ) ;
896
+ } ) ;
897
+
810
898
describe ( 'with provided tabIndex' , ( ) => {
811
899
let checkboxDebugElement : DebugElement ;
812
900
let checkboxNativeElement : HTMLElement ;
@@ -1237,6 +1325,38 @@ class CheckboxWithAriaLabelledby {}
1237
1325
} )
1238
1326
class CheckboxWithAriaDescribedby { }
1239
1327
1328
+ /** Simple test component with an aria-expanded set with true. */
1329
+ @Component ( {
1330
+ template : `<mat-checkbox aria-expanded="true"></mat-checkbox>` ,
1331
+ standalone : true ,
1332
+ imports : [ MatCheckbox ] ,
1333
+ } )
1334
+ class CheckboxWithPositiveAriaExpanded { }
1335
+
1336
+ /** Simple test component with an aria-expanded set with false. */
1337
+ @Component ( {
1338
+ template : `<mat-checkbox aria-expanded="false"></mat-checkbox>` ,
1339
+ standalone : true ,
1340
+ imports : [ MatCheckbox ] ,
1341
+ } )
1342
+ class CheckboxWithNegativeAriaExpanded { }
1343
+
1344
+ /** Simple test component with an aria-controls set. */
1345
+ @Component ( {
1346
+ template : `<mat-checkbox aria-controls="some-id"></mat-checkbox>` ,
1347
+ standalone : true ,
1348
+ imports : [ MatCheckbox ] ,
1349
+ } )
1350
+ class CheckboxWithAriaControls { }
1351
+
1352
+ /** Simple test component with an aria-owns set. */
1353
+ @Component ( {
1354
+ template : `<mat-checkbox aria-owns="some-id"></mat-checkbox>` ,
1355
+ standalone : true ,
1356
+ imports : [ MatCheckbox ] ,
1357
+ } )
1358
+ class CheckboxWithAriaOwns { }
1359
+
1240
1360
/** Simple test component with name attribute */
1241
1361
@Component ( {
1242
1362
template : `<mat-checkbox name="test-name"></mat-checkbox>` ,
0 commit comments