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 #7130.
  • Loading branch information
crisbeto committed Sep 29, 2017
1 parent 53c42a4 commit 734d808
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
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
7 changes: 7 additions & 0 deletions src/lib/radio/radio.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -711,6 +717,7 @@ class RadiosInsideRadioGroup {
[aria-labelledby]="ariaLabelledby">
</mat-radio-button>
<mat-radio-button name="fruit" value="raspberry">Raspberry</mat-radio-button>
<mat-radio-button id="nameless" value="no-name">No name</mat-radio-button>
`
})
class StandaloneRadioButtons {
Expand Down

0 comments on commit 734d808

Please sign in to comment.