Skip to content

Commit

Permalink
fix(material/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 Feb 28, 2024
1 parent 09111d0 commit ec1c6c4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/material/checkbox/checkbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,12 @@ describe('MDC-based MatCheckbox', () => {

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/material/checkbox/checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const defaults = MAT_CHECKBOX_DEFAULT_OPTIONS_FACTORY();
'[attr.tabindex]': 'null',
'[attr.aria-label]': 'null',
'[attr.aria-labelledby]': 'null',
'[attr.name]': 'null',
'[class._mat-animation-noopable]': `_animationMode === 'NoopAnimations'`,
'[class.mdc-checkbox--disabled]': 'disabled',
'[id]': 'id',
Expand Down

0 comments on commit ec1c6c4

Please sign in to comment.