@@ -409,6 +409,20 @@ describe('MatRadio', () => {
409409 }
410410 } ) ;
411411
412+ it ( 'should update the name of radio DOM elements if the name of the group changes' , ( ) => {
413+ const nodes : HTMLInputElement [ ] = innerRadios . map ( radio => radio . nativeElement ) ;
414+
415+ expect ( nodes . every ( radio => radio . getAttribute ( 'name' ) === groupInstance . name ) )
416+ . toBe ( true , 'Expected all radios to have the initial name.' ) ;
417+
418+ fixture . componentInstance . groupName = 'changed-name' ;
419+ fixture . detectChanges ( ) ;
420+
421+ expect ( groupInstance . name ) . toBe ( 'changed-name' ) ;
422+ expect ( nodes . every ( radio => radio . getAttribute ( 'name' ) === groupInstance . name ) )
423+ . toBe ( true , 'Expected all radios to have the new name.' ) ;
424+ } ) ;
425+
412426 it ( 'should check the corresponding radio button on group value change' , ( ) => {
413427 expect ( groupInstance . value ) . toBeFalsy ( ) ;
414428 for ( const radio of radioInstances ) {
@@ -814,7 +828,7 @@ class StandaloneRadioButtons {
814828
815829@Component ( {
816830 template : `
817- <mat-radio-group [(ngModel)]="modelValue" (change)="lastEvent = $event">
831+ <mat-radio-group [name]="groupName" [ (ngModel)]="modelValue" (change)="lastEvent = $event">
818832 <mat-radio-button *ngFor="let option of options" [value]="option.value">
819833 {{option.label}}
820834 </mat-radio-button>
@@ -823,6 +837,7 @@ class StandaloneRadioButtons {
823837} )
824838class RadioGroupWithNgModel {
825839 modelValue : string ;
840+ groupName = 'radio-group' ;
826841 options = [
827842 { label : 'Vanilla' , value : 'vanilla' } ,
828843 { label : 'Chocolate' , value : 'chocolate' } ,
0 commit comments