Skip to content

Commit c5e162b

Browse files
crisbetoandrewseguin
authored andcommitted
fix(radio): defaulting to invalid name attribute (#7131)
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 c5c96d9 commit c5e162b

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,12 @@ describe('MatRadio', () => {
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
</mat-radio-button>
713719
<mat-radio-button name="fruit" value="raspberry">Raspberry</mat-radio-button>
720+
<mat-radio-button id="nameless" value="no-name">No name</mat-radio-button>
714721
`
715722
})
716723
class StandaloneRadioButtons {

0 commit comments

Comments
 (0)