Skip to content

Commit 2fbcbd1

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 177a433 commit 2fbcbd1

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
@@ -1041,6 +1041,12 @@ describe('MatSlideToggle with forms', () => {
10411041

10421042
expect(testComponent.isSubmitted).toBe(true);
10431043
});
1044+
1045+
it('should clear static name attribute from the slide toggle host node', () => {
1046+
const hostNode = fixture.nativeElement.querySelector('.mat-slide-toggle');
1047+
expect(inputElement.getAttribute('name')).toBeTruthy();
1048+
expect(hostNode.hasAttribute('name')).toBe(false);
1049+
});
10441050
});
10451051

10461052
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
@@ -88,6 +88,7 @@ export const _MatSlideToggleMixinBase:
8888
'[id]': 'id',
8989
// Needs to be `-1` so it can still receive programmatic focus.
9090
'[attr.tabindex]': 'disabled ? null : -1',
91+
'[attr.name]': 'null',
9192
'[class.mat-checked]': 'checked',
9293
'[class.mat-disabled]': 'disabled',
9394
'[class.mat-slide-toggle-label-before]': 'labelPosition == "before"',

0 commit comments

Comments
 (0)