@@ -18,6 +18,8 @@ describe('MatRadio', () => {
18
18
RadioGroupWithNgModel ,
19
19
RadioGroupWithFormControl ,
20
20
StandaloneRadioButtons ,
21
+ InterleavedRadioGroup ,
22
+ TranscludingWrapper
21
23
] ,
22
24
providers : [
23
25
{ provide : ViewportRuler , useClass : FakeViewportRuler }
@@ -666,6 +668,28 @@ describe('MatRadio', () => {
666
668
expect ( document . activeElement ) . toBe ( inputEl ) ;
667
669
} ) ;
668
670
} ) ;
671
+
672
+ describe ( 'group interspersed with other tags' , ( ) => {
673
+ let fixture : ComponentFixture < InterleavedRadioGroup > ;
674
+ let groupDebugElement : DebugElement ;
675
+ let groupInstance : MatRadioGroup ;
676
+ let radioDebugElements : DebugElement [ ] ;
677
+ let radioInstances : MatRadioButton [ ] ;
678
+
679
+ beforeEach ( async ( ( ) => {
680
+ fixture = TestBed . createComponent ( InterleavedRadioGroup ) ;
681
+ fixture . detectChanges ( ) ;
682
+
683
+ groupDebugElement = fixture . debugElement . query ( By . directive ( MatRadioGroup ) ) ;
684
+ groupInstance = groupDebugElement . injector . get < MatRadioGroup > ( MatRadioGroup ) ;
685
+ radioDebugElements = fixture . debugElement . queryAll ( By . directive ( MatRadioButton ) ) ;
686
+ radioInstances = radioDebugElements . map ( debugEl => debugEl . componentInstance ) ;
687
+ } ) ) ;
688
+
689
+ it ( 'should initialize selection of radios based on model value' , ( ) => {
690
+ expect ( groupInstance . selected ) . toBe ( radioInstances [ 2 ] ) ;
691
+ } ) ;
692
+ } ) ;
669
693
} ) ;
670
694
671
695
@@ -760,3 +784,29 @@ class RadioGroupWithFormControl {
760
784
template : `<mat-radio-button tabindex="-1"></mat-radio-button>`
761
785
} )
762
786
class FocusableRadioButton { }
787
+
788
+ @Component ( {
789
+ template : `
790
+ <mat-radio-group name="group" [(ngModel)]="modelValue">
791
+ <transcluding-wrapper *ngFor="let option of options">
792
+ <mat-radio-button [value]="option.value">{{option.label}}</mat-radio-button>
793
+ </transcluding-wrapper>
794
+ </mat-radio-group>
795
+ `
796
+ } )
797
+ class InterleavedRadioGroup {
798
+ modelValue = 'strawberry' ;
799
+ options = [
800
+ { label : 'Vanilla' , value : 'vanilla' } ,
801
+ { label : 'Chocolate' , value : 'chocolate' } ,
802
+ { label : 'Strawberry' , value : 'strawberry' } ,
803
+ ] ;
804
+ }
805
+
806
+ @Component ( {
807
+ selector : 'transcluding-wrapper' ,
808
+ template : `
809
+ <div><ng-content></ng-content></div>
810
+ `
811
+ } )
812
+ class TranscludingWrapper { }
0 commit comments