-
Notifications
You must be signed in to change notification settings - Fork 6.8k
fix(button-toggle): use native button and aria-pressed for button-toggle #10990
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
Conversation
(change)="_onInputChange($event)" | ||
(click)="_onInputClick($event)"> | ||
|
||
<button #button class="mat-button-toggle-button" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs type="button"
, otherwise it'll submit any parent form elements when it's toggled.
}); | ||
|
||
it('should have correct aria-pressed attribute', () => { | ||
expect(buttonToggleNativeElement.querySelector('button')!.getAttribute('aria-pressed')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can move out the buttonToggleNativeElement.querySelector('button')
into a variable since it'll always point to the same element.
8eb1dd7
to
d531fad
Compare
Comments addressed. Thanks for review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The
role
on the parent element also needs to change. Right now it will useradiogroup
for single-selection, which have to containrole="radio"
. I guess it should just begroup
all the time now. - Is there anything that now communicates that the group supports single or multiple selection?
[id]="buttonId" | ||
[attr.aria-pressed]="checked" | ||
[disabled]="disabled || null" | ||
[attr.name]="name" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to bind name
without attr.
because it is a DOM property
d531fad
to
747bc0f
Compare
Changed to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Just tried it out in VoiceOver and it works great.
/** Unique ID for the underlying `input` element. */ | ||
get inputId(): string { return `${this.id}-input`; } | ||
/** Unique ID for the underlying `button` element. */ | ||
get buttonId(): string { return `${this.id}-button`; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a change to the public API and needs to be aliased and marked deprecated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, I missed that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
Updated and marked deprecated.
747bc0f
to
92b5e9d
Compare
@tinayuangao looks like a small lint error (missing semi-colon) |
92b5e9d
to
2d3ea59
Compare
@tinayuangao can you look at the failures on this PR? |
2d3ea59
to
18bbb93
Compare
18bbb93
to
8ffb4ef
Compare
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
No description provided.