Skip to content

Commit ec1c6c4

Browse files
committed
fix(material/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 09111d0 commit ec1c6c4

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/material/checkbox/checkbox.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,12 @@ describe('MDC-based MatCheckbox', () => {
959959

960960
expect(inputElement.getAttribute('name')).toBe('test-name');
961961
}));
962+
963+
it('should clear the name attribute from the host node', () => {
964+
const checkboxElement = fixture.debugElement.query(By.directive(MatCheckbox));
965+
966+
expect(checkboxElement.nativeElement.getAttribute('name')).toBeFalsy();
967+
});
962968
});
963969

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

src/material/checkbox/checkbox.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const defaults = MAT_CHECKBOX_DEFAULT_OPTIONS_FACTORY();
9292
'[attr.tabindex]': 'null',
9393
'[attr.aria-label]': 'null',
9494
'[attr.aria-labelledby]': 'null',
95+
'[attr.name]': 'null',
9596
'[class._mat-animation-noopable]': `_animationMode === 'NoopAnimations'`,
9697
'[class.mdc-checkbox--disabled]': 'disabled',
9798
'[id]': 'id',

0 commit comments

Comments
 (0)