@@ -15,6 +15,7 @@ describe('MdRadio', () => {
15
15
TestBed . configureTestingModule ( {
16
16
imports : [ MdRadioModule , FormsModule , ReactiveFormsModule ] ,
17
17
declarations : [
18
+ FocusableRadioButton ,
18
19
RadiosInsideRadioGroup ,
19
20
RadioGroupWithNgModel ,
20
21
RadioGroupWithFormControl ,
@@ -640,6 +641,27 @@ describe('MdRadio', () => {
640
641
}
641
642
} ) ;
642
643
} ) ;
644
+
645
+ describe ( 'with tabindex' , ( ) => {
646
+ let fixture : ComponentFixture < FocusableRadioButton > ;
647
+
648
+ beforeEach ( ( ) => {
649
+ fixture = TestBed . createComponent ( FocusableRadioButton ) ;
650
+ fixture . detectChanges ( ) ;
651
+ } ) ;
652
+
653
+ it ( 'should forward focus to native input' , ( ) => {
654
+ let radioButtonEl = fixture . debugElement . query ( By . css ( '.mat-radio-button' ) ) . nativeElement ;
655
+ let inputEl = fixture . debugElement . query ( By . css ( '.mat-radio-input' ) ) . nativeElement ;
656
+
657
+ radioButtonEl . focus ( ) ;
658
+ // Focus events don't always fire in tests, so we needc to fake it.
659
+ dispatchFakeEvent ( radioButtonEl , 'focus' ) ;
660
+ fixture . detectChanges ( ) ;
661
+
662
+ expect ( document . activeElement ) . toBe ( inputEl ) ;
663
+ } ) ;
664
+ } ) ;
643
665
} ) ;
644
666
645
667
@@ -728,3 +750,8 @@ class RadioGroupWithNgModel {
728
750
class RadioGroupWithFormControl {
729
751
formControl = new FormControl ( ) ;
730
752
}
753
+
754
+ @Component ( {
755
+ template : `<md-radio-button tabindex="-1"></md-radio-button>`
756
+ } )
757
+ class FocusableRadioButton { }
0 commit comments