Skip to content

Commit 171834c

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 3b0f7fc commit 171834c

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,12 @@ describe('MatSlideToggle with forms', () => {
10311031

10321032
expect(testComponent.isSubmitted).toBe(true);
10331033
});
1034+
1035+
it('should clear static name attribute from the slide toggle host node', () => {
1036+
const hostNode = fixture.nativeElement.querySelector('.mat-slide-toggle');
1037+
expect(inputElement.getAttribute('name')).toBeTruthy();
1038+
expect(hostNode.hasAttribute('name')).toBe(false);
1039+
});
10341040
});
10351041

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

src/lib/slide-toggle/slide-toggle.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export const _MatSlideToggleMixinBase:
8787
'class': 'mat-slide-toggle',
8888
'[id]': 'id',
8989
'[attr.tabindex]': '-1', // Needs to be `-1` so it can still receive programmatic focus.
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)