diff --git a/src/material-experimental/mdc-slide-toggle/slide-toggle.spec.ts b/src/material-experimental/mdc-slide-toggle/slide-toggle.spec.ts index de6cef6606fb..d5926a480a92 100644 --- a/src/material-experimental/mdc-slide-toggle/slide-toggle.spec.ts +++ b/src/material-experimental/mdc-slide-toggle/slide-toggle.spec.ts @@ -763,6 +763,12 @@ describe('MDC-based MatSlideToggle with forms', () => { expect(slideToggleEl.classList).toContain('ng-invalid'); expect(slideToggleEl.classList).not.toContain('ng-valid'); }); + + it('should clear static name attribute from the slide toggle host node', () => { + const hostNode = fixture.nativeElement.querySelector('.mat-mdc-slide-toggle'); + expect(inputElement.getAttribute('name')).toBeTruthy(); + expect(hostNode.hasAttribute('name')).toBe(false); + }); }); describe('with model and change event', () => { diff --git a/src/material-experimental/mdc-slide-toggle/slide-toggle.ts b/src/material-experimental/mdc-slide-toggle/slide-toggle.ts index 180886016e1e..e4b82fd855b6 100644 --- a/src/material-experimental/mdc-slide-toggle/slide-toggle.ts +++ b/src/material-experimental/mdc-slide-toggle/slide-toggle.ts @@ -75,6 +75,7 @@ export class MatSlideToggleChange { // Needs to be `-1` so it can still receive programmatic focus. '[attr.tabindex]': 'disabled ? null : -1', '[attr.aria-label]': 'null', + '[attr.name]': 'null', '[attr.aria-labelledby]': 'null', '[class.mat-primary]': 'color === "primary"', '[class.mat-accent]': 'color !== "primary" && color !== "warn"', diff --git a/src/material/slide-toggle/slide-toggle.spec.ts b/src/material/slide-toggle/slide-toggle.spec.ts index d37a2710e2c1..9f6e840ba48e 100644 --- a/src/material/slide-toggle/slide-toggle.spec.ts +++ b/src/material/slide-toggle/slide-toggle.spec.ts @@ -839,6 +839,12 @@ describe('MatSlideToggle with forms', () => { expect(slideToggleEl.classList).toContain('ng-invalid'); expect(slideToggleEl.classList).not.toContain('ng-valid'); }); + + it('should clear static name attribute from the slide toggle host node', () => { + const hostNode = fixture.nativeElement.querySelector('.mat-slide-toggle'); + expect(inputElement.getAttribute('name')).toBeTruthy(); + expect(hostNode.hasAttribute('name')).toBe(false); + }); }); describe('with model and change event', () => { diff --git a/src/material/slide-toggle/slide-toggle.ts b/src/material/slide-toggle/slide-toggle.ts index a3aec7a0ebd4..154f717d718b 100644 --- a/src/material/slide-toggle/slide-toggle.ts +++ b/src/material/slide-toggle/slide-toggle.ts @@ -85,6 +85,7 @@ const _MatSlideToggleMixinBase: '[attr.tabindex]': 'disabled ? null : -1', '[attr.aria-label]': 'null', '[attr.aria-labelledby]': 'null', + '[attr.name]': 'null', '[class.mat-checked]': 'checked', '[class.mat-disabled]': 'disabled', '[class.mat-slide-toggle-label-before]': 'labelPosition == "before"',