Skip to content

Commit b14f79b

Browse files
committed
fix(checkbox): clear name from host node
Currently we forward the name attribute from the host node to the underlying input, however we leave the name on the host node intact. This can throw off functions like `document.getElementsByName` or the `By.name` Protractor selector.
1 parent 612a738 commit b14f79b

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/material/checkbox/checkbox.spec.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -993,11 +993,17 @@ describe('MatCheckbox', () => {
993993
});
994994

995995
it('should forward name value to input element', () => {
996-
let checkboxElement = fixture.debugElement.query(By.directive(MatCheckbox));
997-
let inputElement = <HTMLInputElement> checkboxElement.nativeElement.querySelector('input');
996+
const checkboxElement = fixture.debugElement.query(By.directive(MatCheckbox));
997+
const inputElement = <HTMLInputElement> checkboxElement.nativeElement.querySelector('input');
998998

999999
expect(inputElement.getAttribute('name')).toBe('test-name');
10001000
});
1001+
1002+
it('should clear the name attribute from the host node', () => {
1003+
const checkboxElement = fixture.debugElement.query(By.directive(MatCheckbox));
1004+
1005+
expect(checkboxElement.nativeElement.getAttribute('name')).toBeFalsy();
1006+
});
10011007
});
10021008

10031009
describe('with form control', () => {

src/material/checkbox/checkbox.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ const _MatCheckboxMixinBase:
115115
'class': 'mat-checkbox',
116116
'[id]': 'id',
117117
'[attr.tabindex]': 'null',
118+
'[attr.name]': 'null',
118119
'[class.mat-checkbox-indeterminate]': 'indeterminate',
119120
'[class.mat-checkbox-checked]': 'checked',
120121
'[class.mat-checkbox-disabled]': 'disabled',

0 commit comments

Comments
 (0)