@@ -641,16 +641,12 @@ describe('MDC-based MatCheckbox', () => {
641
641
} ) ) ;
642
642
} ) ;
643
643
644
- describe ( 'aria-label' , ( ) => {
645
- let checkboxDebugElement : DebugElement ;
646
- let checkboxNativeElement : HTMLElement ;
647
- let inputElement : HTMLInputElement ;
648
-
644
+ describe ( 'aria handling' , ( ) => {
649
645
it ( 'should use the provided aria-label' , fakeAsync ( ( ) => {
650
646
fixture = createComponent ( CheckboxWithAriaLabel ) ;
651
- checkboxDebugElement = fixture . debugElement . query ( By . directive ( MatCheckbox ) ) ! ;
652
- checkboxNativeElement = checkboxDebugElement . nativeElement ;
653
- inputElement = < HTMLInputElement > checkboxNativeElement . querySelector ( 'input' ) ;
647
+ const checkboxDebugElement = fixture . debugElement . query ( By . directive ( MatCheckbox ) ) ! ;
648
+ const checkboxNativeElement = checkboxDebugElement . nativeElement ;
649
+ const inputElement = < HTMLInputElement > checkboxNativeElement . querySelector ( 'input' ) ;
654
650
655
651
fixture . detectChanges ( ) ;
656
652
expect ( inputElement . getAttribute ( 'aria-label' ) ) . toBe ( 'Super effective' ) ;
@@ -662,32 +658,35 @@ describe('MDC-based MatCheckbox', () => {
662
658
663
659
expect ( fixture . nativeElement . querySelector ( 'input' ) . hasAttribute ( 'aria-label' ) ) . toBe ( false ) ;
664
660
} ) ) ;
665
- } ) ;
666
-
667
- describe ( 'with provided aria-labelledby ' , ( ) => {
668
- let checkboxDebugElement : DebugElement ;
669
- let checkboxNativeElement : HTMLElement ;
670
- let inputElement : HTMLInputElement ;
671
661
672
662
it ( 'should use the provided aria-labelledby' , fakeAsync ( ( ) => {
673
663
fixture = createComponent ( CheckboxWithAriaLabelledby ) ;
674
- checkboxDebugElement = fixture . debugElement . query ( By . directive ( MatCheckbox ) ) ! ;
675
- checkboxNativeElement = checkboxDebugElement . nativeElement ;
676
- inputElement = < HTMLInputElement > checkboxNativeElement . querySelector ( 'input' ) ;
664
+ const checkboxDebugElement = fixture . debugElement . query ( By . directive ( MatCheckbox ) ) ! ;
665
+ const checkboxNativeElement = checkboxDebugElement . nativeElement ;
666
+ const inputElement = < HTMLInputElement > checkboxNativeElement . querySelector ( 'input' ) ;
677
667
678
668
fixture . detectChanges ( ) ;
679
669
expect ( inputElement . getAttribute ( 'aria-labelledby' ) ) . toBe ( 'some-id' ) ;
680
670
} ) ) ;
681
671
682
672
it ( 'should not assign aria-labelledby if none is provided' , fakeAsync ( ( ) => {
683
673
fixture = createComponent ( SingleCheckbox ) ;
684
- checkboxDebugElement = fixture . debugElement . query ( By . directive ( MatCheckbox ) ) ! ;
685
- checkboxNativeElement = checkboxDebugElement . nativeElement ;
686
- inputElement = < HTMLInputElement > checkboxNativeElement . querySelector ( 'input' ) ;
674
+ const checkboxDebugElement = fixture . debugElement . query ( By . directive ( MatCheckbox ) ) ! ;
675
+ const checkboxNativeElement = checkboxDebugElement . nativeElement ;
676
+ const inputElement = < HTMLInputElement > checkboxNativeElement . querySelector ( 'input' ) ;
687
677
688
678
fixture . detectChanges ( ) ;
689
679
expect ( inputElement . getAttribute ( 'aria-labelledby' ) ) . toBe ( null ) ;
690
680
} ) ) ;
681
+
682
+ it ( 'should clear the static aria attributes from the host node' , ( ) => {
683
+ fixture = createComponent ( CheckboxWithStaticAriaAttributes ) ;
684
+ const checkbox = fixture . debugElement . query ( By . directive ( MatCheckbox ) ) ! . nativeElement ;
685
+ fixture . detectChanges ( ) ;
686
+
687
+ expect ( checkbox . hasAttribute ( 'aria' ) ) . toBe ( false ) ;
688
+ expect ( checkbox . hasAttribute ( 'aria-labelledby' ) ) . toBe ( false ) ;
689
+ } ) ;
691
690
} ) ;
692
691
693
692
describe ( 'with provided aria-describedby ' , ( ) => {
@@ -1147,3 +1146,8 @@ class CheckboxWithoutLabel {
1147
1146
/** Test component with the native tabindex attribute. */
1148
1147
@Component ( { template : `<mat-checkbox tabindex="5"></mat-checkbox>` } )
1149
1148
class CheckboxWithTabindexAttr { }
1149
+
1150
+ @Component ( {
1151
+ template : `<mat-checkbox aria-label="Checkbox" aria-labelledby="something"></mat-checkbox>` ,
1152
+ } )
1153
+ class CheckboxWithStaticAriaAttributes { }
0 commit comments