Skip to content

Commit 23158d8

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 9091330 commit 23158d8

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
@@ -805,6 +805,12 @@ describe('MatSlideToggle with forms', () => {
805805
expect(slideToggleEl.classList).toContain('ng-invalid');
806806
expect(slideToggleEl.classList).not.toContain('ng-valid');
807807
});
808+
809+
it('should clear static name attribute from the slide toggle host node', () => {
810+
const hostNode = fixture.nativeElement.querySelector('.mat-slide-toggle');
811+
expect(inputElement.getAttribute('name')).toBeTruthy();
812+
expect(hostNode.hasAttribute('name')).toBe(false);
813+
});
808814
});
809815

810816
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
'[attr.tabindex]': 'disabled ? null : -1',
8888
'[attr.aria-label]': 'null',
8989
'[attr.aria-labelledby]': 'null',
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)