@@ -607,54 +607,54 @@ describe('MatCheckbox', () => {
607
607
} ) ) ;
608
608
} ) ;
609
609
610
- describe ( 'aria-label' , ( ) => {
611
- let checkboxDebugElement : DebugElement ;
612
- let checkboxNativeElement : HTMLElement ;
613
- let inputElement : HTMLInputElement ;
614
-
610
+ describe ( 'aria handling' , ( ) => {
615
611
it ( 'should use the provided aria-label' , fakeAsync ( ( ) => {
616
- fixture = createComponent ( CheckboxWithAriaLabel ) ;
617
- checkboxDebugElement = fixture . debugElement . query ( By . directive ( MatCheckbox ) ) ! ;
618
- checkboxNativeElement = checkboxDebugElement . nativeElement ;
619
- inputElement = < HTMLInputElement > checkboxNativeElement . querySelector ( 'input' ) ;
612
+ fixture = createComponent ( CheckboxWithAriaLabel ) ;
613
+ const checkboxDebugElement = fixture . debugElement . query ( By . directive ( MatCheckbox ) ) ! ;
614
+ const checkboxNativeElement = checkboxDebugElement . nativeElement ;
615
+ const inputElement = < HTMLInputElement > checkboxNativeElement . querySelector ( 'input' ) ;
620
616
621
- fixture . detectChanges ( ) ;
622
- expect ( inputElement . getAttribute ( 'aria-label' ) ) . toBe ( 'Super effective' ) ;
623
- } ) ) ;
617
+ fixture . detectChanges ( ) ;
618
+ expect ( inputElement . getAttribute ( 'aria-label' ) ) . toBe ( 'Super effective' ) ;
619
+ } ) ) ;
624
620
625
621
it ( 'should not set the aria-label attribute if no value is provided' , fakeAsync ( ( ) => {
626
- fixture = createComponent ( SingleCheckbox ) ;
627
- fixture . detectChanges ( ) ;
628
-
629
- expect ( fixture . nativeElement . querySelector ( 'input' ) . hasAttribute ( 'aria-label' ) )
630
- . toBe ( false ) ;
631
- } ) ) ;
632
- } ) ;
622
+ fixture = createComponent ( SingleCheckbox ) ;
623
+ fixture . detectChanges ( ) ;
633
624
634
- describe ( 'with provided aria-labelledby ' , ( ) => {
635
- let checkboxDebugElement : DebugElement ;
636
- let checkboxNativeElement : HTMLElement ;
637
- let inputElement : HTMLInputElement ;
625
+ expect ( fixture . nativeElement . querySelector ( 'input' ) . hasAttribute ( 'aria-label' ) )
626
+ . toBe ( false ) ;
627
+ } ) ) ;
638
628
639
629
it ( 'should use the provided aria-labelledby' , fakeAsync ( ( ) => {
640
- fixture = createComponent ( CheckboxWithAriaLabelledby ) ;
641
- checkboxDebugElement = fixture . debugElement . query ( By . directive ( MatCheckbox ) ) ! ;
642
- checkboxNativeElement = checkboxDebugElement . nativeElement ;
643
- inputElement = < HTMLInputElement > checkboxNativeElement . querySelector ( 'input' ) ;
630
+ fixture = createComponent ( CheckboxWithAriaLabelledby ) ;
631
+ const checkboxDebugElement = fixture . debugElement . query ( By . directive ( MatCheckbox ) ) ! ;
632
+ const checkboxNativeElement = checkboxDebugElement . nativeElement ;
633
+ const inputElement = < HTMLInputElement > checkboxNativeElement . querySelector ( 'input' ) ;
644
634
645
- fixture . detectChanges ( ) ;
646
- expect ( inputElement . getAttribute ( 'aria-labelledby' ) ) . toBe ( 'some-id' ) ;
647
- } ) ) ;
635
+ fixture . detectChanges ( ) ;
636
+ expect ( inputElement . getAttribute ( 'aria-labelledby' ) ) . toBe ( 'some-id' ) ;
637
+ } ) ) ;
648
638
649
639
it ( 'should not assign aria-labelledby if none is provided' , fakeAsync ( ( ) => {
650
- fixture = createComponent ( SingleCheckbox ) ;
651
- checkboxDebugElement = fixture . debugElement . query ( By . directive ( MatCheckbox ) ) ! ;
652
- checkboxNativeElement = checkboxDebugElement . nativeElement ;
653
- inputElement = < HTMLInputElement > checkboxNativeElement . querySelector ( 'input' ) ;
640
+ fixture = createComponent ( SingleCheckbox ) ;
641
+ const checkboxDebugElement = fixture . debugElement . query ( By . directive ( MatCheckbox ) ) ! ;
642
+ const checkboxNativeElement = checkboxDebugElement . nativeElement ;
643
+ const inputElement = < HTMLInputElement > checkboxNativeElement . querySelector ( 'input' ) ;
644
+
645
+ fixture . detectChanges ( ) ;
646
+ expect ( inputElement . getAttribute ( 'aria-labelledby' ) ) . toBe ( null ) ;
647
+ } ) ) ;
648
+
649
+ it ( 'should clear the static aria attributes from the host node' , ( ) => {
650
+ fixture = createComponent ( CheckboxWithStaticAriaAttributes ) ;
651
+ const checkbox = fixture . debugElement . query ( By . directive ( MatCheckbox ) ) ! . nativeElement ;
652
+ fixture . detectChanges ( ) ;
653
+
654
+ expect ( checkbox . hasAttribute ( 'aria' ) ) . toBe ( false ) ;
655
+ expect ( checkbox . hasAttribute ( 'aria-labelledby' ) ) . toBe ( false ) ;
656
+ } ) ;
654
657
655
- fixture . detectChanges ( ) ;
656
- expect ( inputElement . getAttribute ( 'aria-labelledby' ) ) . toBe ( null ) ;
657
- } ) ) ;
658
658
} ) ;
659
659
660
660
describe ( 'with provided tabIndex' , ( ) => {
@@ -1049,3 +1049,8 @@ class CheckboxWithoutLabel {
1049
1049
@Component ( { template : `<mat-checkbox tabindex="5"></mat-checkbox>` } )
1050
1050
class CheckboxWithTabindexAttr {
1051
1051
}
1052
+
1053
+ @Component ( {
1054
+ template : `<mat-checkbox aria-label="Checkbox" aria-labelledby="something"></mat-checkbox>`
1055
+ } )
1056
+ class CheckboxWithStaticAriaAttributes { }
0 commit comments