Skip to content

Commit fda978a

Browse files
crisbetojelbourn
authored andcommitted
fix(button-toggle): inaccurate name passed down to input if no name is assigned (#9017)
Fixes the button toggle setting the underlying input's name to `"undefined"` if the consumer hasn't passed in a name.
1 parent 6f8f226 commit fda978a

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/lib/button-toggle/button-toggle.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[id]="inputId"
55
[checked]="checked"
66
[disabled]="disabled || null"
7-
[name]="name"
7+
[attr.name]="name"
88
[attr.aria-label]="ariaLabel"
99
[attr.aria-labelledby]="ariaLabelledby"
1010
(change)="_onInputChange($event)"

src/lib/button-toggle/button-toggle.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,10 @@ describe('MatButtonToggle without forms', () => {
578578
expect(document.activeElement).toBe(nativeRadioInput);
579579
});
580580

581+
it('should not assign a name to the underlying input if one is not passed in', () => {
582+
expect(buttonToggleNativeElement.querySelector('input')!.getAttribute('name')).toBeFalsy();
583+
});
584+
581585
});
582586

583587
describe('with provided aria-label ', () => {

0 commit comments

Comments
 (0)