From 04b4c7d812297e37ccf1d2f55e636e4babc189fc Mon Sep 17 00:00:00 2001 From: crisbeto Date: Sat, 16 Dec 2017 17:50:49 +0100 Subject: [PATCH] fix(button-toggle): inaccurate name passed down to input if no name is assigned Fixes the button toggle setting the underlying input's name to `"undefined"` if the consumer hasn't passed in a name. --- src/lib/button-toggle/button-toggle.html | 2 +- src/lib/button-toggle/button-toggle.spec.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/button-toggle/button-toggle.html b/src/lib/button-toggle/button-toggle.html index 2b284229dc5e..bede64573525 100644 --- a/src/lib/button-toggle/button-toggle.html +++ b/src/lib/button-toggle/button-toggle.html @@ -4,7 +4,7 @@ [id]="inputId" [checked]="checked" [disabled]="disabled || null" - [name]="name" + [attr.name]="name" [attr.aria-label]="ariaLabel" [attr.aria-labelledby]="ariaLabelledby" (change)="_onInputChange($event)" diff --git a/src/lib/button-toggle/button-toggle.spec.ts b/src/lib/button-toggle/button-toggle.spec.ts index f6031f5bf983..818a98026f96 100644 --- a/src/lib/button-toggle/button-toggle.spec.ts +++ b/src/lib/button-toggle/button-toggle.spec.ts @@ -578,6 +578,10 @@ describe('MatButtonToggle without forms', () => { expect(document.activeElement).toBe(nativeRadioInput); }); + it('should not assign a name to the underlying input if one is not passed in', () => { + expect(buttonToggleNativeElement.querySelector('input')!.getAttribute('name')).toBeFalsy(); + }); + }); describe('with provided aria-label ', () => {