Skip to content

Commit

Permalink
fix(slide-toggle): clear name from host node
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
crisbeto committed Mar 16, 2019
1 parent 3b0f7fc commit 171834c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/lib/slide-toggle/slide-toggle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,12 @@ describe('MatSlideToggle with forms', () => {

expect(testComponent.isSubmitted).toBe(true);
});

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', () => {
Expand Down
1 change: 1 addition & 0 deletions src/lib/slide-toggle/slide-toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export const _MatSlideToggleMixinBase:
'class': 'mat-slide-toggle',
'[id]': 'id',
'[attr.tabindex]': '-1', // Needs to be `-1` so it can still receive programmatic focus.
'[attr.name]': 'null',
'[class.mat-checked]': 'checked',
'[class.mat-disabled]': 'disabled',
'[class.mat-slide-toggle-label-before]': 'labelPosition == "before"',
Expand Down

0 comments on commit 171834c

Please sign in to comment.