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