Skip to content

Commit a7504de

Browse files
committed
fix(slide-toggle): clear name from host node
Along the same lines as #15422 and #15368. Clears the static `name` attribute from the slide toggle's host node in order to prevent both the underlying input and the host from showing up in `document.getElementsByName` or `By.name`.
1 parent d9977bd commit a7504de

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/material/slide-toggle/slide-toggle.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,12 @@ describe('MatSlideToggle with forms', () => {
10671067
expect(slideToggleEl.classList).toContain('ng-invalid');
10681068
expect(slideToggleEl.classList).not.toContain('ng-valid');
10691069
});
1070+
1071+
it('should clear static name attribute from the slide toggle host node', () => {
1072+
const hostNode = fixture.nativeElement.querySelector('.mat-slide-toggle');
1073+
expect(inputElement.getAttribute('name')).toBeTruthy();
1074+
expect(hostNode.hasAttribute('name')).toBe(false);
1075+
});
10701076
});
10711077

10721078
describe('with model and change event', () => {

src/material/slide-toggle/slide-toggle.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ const _MatSlideToggleMixinBase:
8787
'[id]': 'id',
8888
// Needs to be `-1` so it can still receive programmatic focus.
8989
'[attr.tabindex]': 'disabled ? null : -1',
90+
'[attr.name]': 'null',
9091
'[class.mat-checked]': 'checked',
9192
'[class.mat-disabled]': 'disabled',
9293
'[class.mat-slide-toggle-label-before]': 'labelPosition == "before"',

0 commit comments

Comments
 (0)