Skip to content

Commit

Permalink
fix(radio): defaulting to invalid name attribute
Browse files Browse the repository at this point in the history
Fixes the radio button defaulting to `name="undefined"` for the underlying input, if the consumer hasn't passed in a name.

Relates to angular#7130.
  • Loading branch information
crisbeto committed Sep 17, 2017
1 parent df808b8 commit 8f09ca3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/lib/radio/radio.html
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 8 additions & 1 deletion src/lib/radio/radio.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {dispatchFakeEvent, FakeViewportRuler} from '@angular/cdk/testing';
import {RIPPLE_FADE_IN_DURATION, RIPPLE_FADE_OUT_DURATION} from '@angular/material/core';
import {MdRadioButton, MdRadioChange, MdRadioGroup, MdRadioModule} from './index';

describe('MdRadio', () => {
fdescribe('MdRadio', () => {

beforeEach(async(() => {
TestBed.configureTestingModule({
Expand Down Expand Up @@ -638,6 +638,12 @@ describe('MdRadio', () => {
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', () => {
Expand Down Expand Up @@ -711,6 +717,7 @@ class RadiosInsideRadioGroup {
[aria-labelledby]="ariaLabelledby">
</md-radio-button>
<md-radio-button name="fruit" value="raspberry">Raspberry</md-radio-button>
<md-radio-button id="nameless" value="no-name">No name</md-radio-button>
`
})
class StandaloneRadioButtons {
Expand Down

0 comments on commit 8f09ca3

Please sign in to comment.