@@ -641,16 +641,12 @@ describe('MDC-based MatCheckbox', () => {
641641 } ) ) ;
642642 } ) ;
643643
644- describe ( 'aria-label' , ( ) => {
645- let checkboxDebugElement : DebugElement ;
646- let checkboxNativeElement : HTMLElement ;
647- let inputElement : HTMLInputElement ;
648-
644+ describe ( 'aria handling' , ( ) => {
649645 it ( 'should use the provided aria-label' , fakeAsync ( ( ) => {
650646 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' ) ;
654650
655651 fixture . detectChanges ( ) ;
656652 expect ( inputElement . getAttribute ( 'aria-label' ) ) . toBe ( 'Super effective' ) ;
@@ -662,32 +658,35 @@ describe('MDC-based MatCheckbox', () => {
662658
663659 expect ( fixture . nativeElement . querySelector ( 'input' ) . hasAttribute ( 'aria-label' ) ) . toBe ( false ) ;
664660 } ) ) ;
665- } ) ;
666-
667- describe ( 'with provided aria-labelledby ' , ( ) => {
668- let checkboxDebugElement : DebugElement ;
669- let checkboxNativeElement : HTMLElement ;
670- let inputElement : HTMLInputElement ;
671661
672662 it ( 'should use the provided aria-labelledby' , fakeAsync ( ( ) => {
673663 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' ) ;
677667
678668 fixture . detectChanges ( ) ;
679669 expect ( inputElement . getAttribute ( 'aria-labelledby' ) ) . toBe ( 'some-id' ) ;
680670 } ) ) ;
681671
682672 it ( 'should not assign aria-labelledby if none is provided' , fakeAsync ( ( ) => {
683673 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' ) ;
687677
688678 fixture . detectChanges ( ) ;
689679 expect ( inputElement . getAttribute ( 'aria-labelledby' ) ) . toBe ( null ) ;
690680 } ) ) ;
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+ } ) ;
691690 } ) ;
692691
693692 describe ( 'with provided aria-describedby ' , ( ) => {
@@ -1147,3 +1146,8 @@ class CheckboxWithoutLabel {
11471146/** Test component with the native tabindex attribute. */
11481147@Component ( { template : `<mat-checkbox tabindex="5"></mat-checkbox>` } )
11491148class CheckboxWithTabindexAttr { }
1149+
1150+ @Component ( {
1151+ template : `<mat-checkbox aria-label="Checkbox" aria-labelledby="something"></mat-checkbox>` ,
1152+ } )
1153+ class CheckboxWithStaticAriaAttributes { }
0 commit comments