@@ -409,6 +409,20 @@ describe('MatRadio', () => {
409
409
}
410
410
} ) ;
411
411
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
+
412
426
it ( 'should check the corresponding radio button on group value change' , ( ) => {
413
427
expect ( groupInstance . value ) . toBeFalsy ( ) ;
414
428
for ( const radio of radioInstances ) {
@@ -814,7 +828,7 @@ class StandaloneRadioButtons {
814
828
815
829
@Component ( {
816
830
template : `
817
- <mat-radio-group [(ngModel)]="modelValue" (change)="lastEvent = $event">
831
+ <mat-radio-group [name]="groupName" [ (ngModel)]="modelValue" (change)="lastEvent = $event">
818
832
<mat-radio-button *ngFor="let option of options" [value]="option.value">
819
833
{{option.label}}
820
834
</mat-radio-button>
@@ -823,6 +837,7 @@ class StandaloneRadioButtons {
823
837
} )
824
838
class RadioGroupWithNgModel {
825
839
modelValue : string ;
840
+ groupName = 'radio-group' ;
826
841
options = [
827
842
{ label : 'Vanilla' , value : 'vanilla' } ,
828
843
{ label : 'Chocolate' , value : 'chocolate' } ,
0 commit comments