Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(button-toggle): clear name from host node #15668

Merged
merged 1 commit into from
May 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/material/button-toggle/button-toggle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ describe('MatButtonToggle without forms', () => {
ButtonToggleWithAriaLabelledby,
RepeatedButtonTogglesWithPreselectedValue,
ButtonToggleWithTabindex,
ButtonToggleWithStaticName,
],
});

Expand Down Expand Up @@ -736,7 +737,7 @@ describe('MatButtonToggle without forms', () => {
});
});

describe('with tabindex ', () => {
describe('with tabindex', () => {
it('should forward the tabindex to the underlying button', () => {
const fixture = TestBed.createComponent(ButtonToggleWithTabindex);
fixture.detectChanges();
Expand Down Expand Up @@ -778,6 +779,16 @@ describe('MatButtonToggle without forms', () => {
expect(fixture.componentInstance.toggles.toArray()[1].checked).toBe(true);
});

it('should not throw on init when toggles are repeated and there is an initial value', () => {
const fixture = TestBed.createComponent(ButtonToggleWithStaticName);
fixture.detectChanges();

const hostNode: HTMLElement = fixture.nativeElement.querySelector('.mat-button-toggle');

expect(hostNode.hasAttribute('name')).toBe(false);
expect(hostNode.querySelector('button')!.getAttribute('name')).toBe('custom-name');
});

it('should maintain the selected state when the value and toggles are swapped out at ' +
'the same time', () => {
const fixture = TestBed.createComponent(RepeatedButtonTogglesWithPreselectedValue);
Expand Down Expand Up @@ -951,3 +962,7 @@ class RepeatedButtonTogglesWithPreselectedValue {
})
class ButtonToggleWithTabindex {}

@Component({
template: `<mat-button-toggle name="custom-name"></mat-button-toggle>`
})
class ButtonToggleWithStaticName {}
1 change: 1 addition & 0 deletions src/material/button-toggle/button-toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ const _MatButtonToggleMixinBase: CanDisableRippleCtor & typeof MatButtonToggleBa
// but can still receive focus from things like cdkFocusInitial.
'[attr.tabindex]': '-1',
'[attr.id]': 'id',
'[attr.name]': 'null',
'(focus)': 'focus()',
}
})
Expand Down