Skip to content

Commit

Permalink
fix(checkbox): clear name from host node
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
crisbeto committed Mar 2, 2019
1 parent ae41a0a commit faab92a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/lib/checkbox/checkbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -993,11 +993,17 @@ describe('MatCheckbox', () => {
});

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

expect(inputElement.getAttribute('name')).toBe('test-name');
});

it('should clear the name attribute from the host node', () => {
const checkboxElement = fixture.debugElement.query(By.directive(MatCheckbox));

expect(checkboxElement.nativeElement.getAttribute('name')).toBeFalsy();
});
});

describe('with form control', () => {
Expand Down
1 change: 1 addition & 0 deletions src/lib/checkbox/checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export const _MatCheckboxMixinBase:
'class': 'mat-checkbox',
'[id]': 'id',
'[attr.tabindex]': 'null',
'[attr.name]': 'null',
'[class.mat-checkbox-indeterminate]': 'indeterminate',
'[class.mat-checkbox-checked]': 'checked',
'[class.mat-checkbox-disabled]': 'disabled',
Expand Down

0 comments on commit faab92a

Please sign in to comment.