@@ -218,6 +218,8 @@ describe('MdButtonToggle without forms', () => {
218
218
ButtonTogglesInsideButtonToggleGroupMultiple ,
219
219
ButtonToggleGroupWithInitialValue ,
220
220
StandaloneButtonToggle ,
221
+ ButtonToggleWithAriaLabel ,
222
+ ButtonToggleWithAriaLabelledby ,
221
223
] ,
222
224
} ) ;
223
225
@@ -592,8 +594,49 @@ describe('MdButtonToggle without forms', () => {
592
594
} ) ;
593
595
594
596
} ) ;
595
- } ) ;
596
597
598
+ describe ( 'with provided aria-label ' , ( ) => {
599
+ let checkboxDebugElement : DebugElement ;
600
+ let checkboxNativeElement : HTMLElement ;
601
+ let inputElement : HTMLInputElement ;
602
+
603
+ it ( 'should use the provided aria-label' , ( ) => {
604
+ let fixture = TestBed . createComponent ( ButtonToggleWithAriaLabel ) ;
605
+ checkboxDebugElement = fixture . debugElement . query ( By . directive ( MdButtonToggle ) ) ;
606
+ checkboxNativeElement = checkboxDebugElement . nativeElement ;
607
+ inputElement = checkboxNativeElement . querySelector ( 'input' ) as HTMLInputElement ;
608
+
609
+ fixture . detectChanges ( ) ;
610
+ expect ( inputElement . getAttribute ( 'aria-label' ) ) . toBe ( 'Super effective' ) ;
611
+ } ) ;
612
+ } ) ;
613
+
614
+ describe ( 'with provided aria-labelledby ' , ( ) => {
615
+ let checkboxDebugElement : DebugElement ;
616
+ let checkboxNativeElement : HTMLElement ;
617
+ let inputElement : HTMLInputElement ;
618
+
619
+ it ( 'should use the provided aria-labelledby' , ( ) => {
620
+ let fixture = TestBed . createComponent ( ButtonToggleWithAriaLabelledby ) ;
621
+ checkboxDebugElement = fixture . debugElement . query ( By . directive ( MdButtonToggle ) ) ;
622
+ checkboxNativeElement = checkboxDebugElement . nativeElement ;
623
+ inputElement = checkboxNativeElement . querySelector ( 'input' ) as HTMLInputElement ;
624
+
625
+ fixture . detectChanges ( ) ;
626
+ expect ( inputElement . getAttribute ( 'aria-labelledby' ) ) . toBe ( 'some-id' ) ;
627
+ } ) ;
628
+
629
+ it ( 'should not assign aria-labelledby if none is provided' , ( ) => {
630
+ let fixture = TestBed . createComponent ( StandaloneButtonToggle ) ;
631
+ checkboxDebugElement = fixture . debugElement . query ( By . directive ( MdButtonToggle ) ) ;
632
+ checkboxNativeElement = checkboxDebugElement . nativeElement ;
633
+ inputElement = checkboxNativeElement . querySelector ( 'input' ) as HTMLInputElement ;
634
+
635
+ fixture . detectChanges ( ) ;
636
+ expect ( inputElement . getAttribute ( 'aria-labelledby' ) ) . toBe ( null ) ;
637
+ } ) ;
638
+ } ) ;
639
+ } ) ;
597
640
598
641
@Component ( {
599
642
template : `
@@ -674,3 +717,15 @@ class ButtonToggleGroupWithInitialValue {
674
717
class ButtonToggleGroupWithFormControl {
675
718
control = new FormControl ( ) ;
676
719
}
720
+
721
+ /** Simple test component with an aria-label set. */
722
+ @Component ( {
723
+ template : `<md-button-toggle aria-label="Super effective"></md-button-toggle>`
724
+ } )
725
+ class ButtonToggleWithAriaLabel { }
726
+
727
+ /** Simple test component with an aria-label set. */
728
+ @Component ( {
729
+ template : `<md-button-toggle aria-labelledby="some-id"></md-button-toggle>`
730
+ } )
731
+ class ButtonToggleWithAriaLabelledby { }
0 commit comments