Skip to content

Commit 8f09ca3

Browse files
committed
fix(radio): defaulting to invalid name attribute
Fixes the radio button defaulting to `name="undefined"` for the underlying input, if the consumer hasn't passed in a name. Relates to #7130.
1 parent df808b8 commit 8f09ca3

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/lib/radio/radio.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
[id]="inputId"
1616
[checked]="checked"
1717
[disabled]="disabled"
18-
[name]="name"
18+
[attr.name]="name"
1919
[required]="required"
2020
[attr.aria-label]="ariaLabel"
2121
[attr.aria-labelledby]="ariaLabelledby"

src/lib/radio/radio.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {dispatchFakeEvent, FakeViewportRuler} from '@angular/cdk/testing';
77
import {RIPPLE_FADE_IN_DURATION, RIPPLE_FADE_OUT_DURATION} from '@angular/material/core';
88
import {MdRadioButton, MdRadioChange, MdRadioGroup, MdRadioModule} from './index';
99

10-
describe('MdRadio', () => {
10+
fdescribe('MdRadio', () => {
1111

1212
beforeEach(async(() => {
1313
TestBed.configureTestingModule({
@@ -638,6 +638,12 @@ describe('MdRadio', () => {
638638
expect(document.activeElement).toBe(fruitRadioNativeInputs[i]);
639639
}
640640
});
641+
642+
it('should not add the "name" attribute if it is not passed in', () => {
643+
const radio = fixture.debugElement.nativeElement.querySelector('#nameless input');
644+
expect(radio.hasAttribute('name')).toBe(false);
645+
});
646+
641647
});
642648

643649
describe('with tabindex', () => {
@@ -711,6 +717,7 @@ class RadiosInsideRadioGroup {
711717
[aria-labelledby]="ariaLabelledby">
712718
</md-radio-button>
713719
<md-radio-button name="fruit" value="raspberry">Raspberry</md-radio-button>
720+
<md-radio-button id="nameless" value="no-name">No name</md-radio-button>
714721
`
715722
})
716723
class StandaloneRadioButtons {

0 commit comments

Comments
 (0)