diff --git a/src/lib/radio/radio.html b/src/lib/radio/radio.html index c6280776061..bd68e10b34f 100644 --- a/src/lib/radio/radio.html +++ b/src/lib/radio/radio.html @@ -15,7 +15,7 @@ [id]="inputId" [checked]="checked" [disabled]="disabled" - [name]="name" + [attr.name]="name" [required]="required" [attr.aria-label]="ariaLabel" [attr.aria-labelledby]="ariaLabelledby" diff --git a/src/lib/radio/radio.spec.ts b/src/lib/radio/radio.spec.ts index 96f0447a9f3..88c3b1175a8 100644 --- a/src/lib/radio/radio.spec.ts +++ b/src/lib/radio/radio.spec.ts @@ -638,6 +638,12 @@ describe('MatRadio', () => { expect(document.activeElement).toBe(fruitRadioNativeInputs[i]); } }); + + it('should not add the "name" attribute if it is not passed in', () => { + const radio = fixture.debugElement.nativeElement.querySelector('#nameless input'); + expect(radio.hasAttribute('name')).toBe(false); + }); + }); describe('with tabindex', () => { @@ -711,6 +717,7 @@ class RadiosInsideRadioGroup { [aria-labelledby]="ariaLabelledby"> Raspberry + No name ` }) class StandaloneRadioButtons {