-
Notifications
You must be signed in to change notification settings - Fork 6.8k
fix(dialog): don't assign aria-label to close button if button has text #11093
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(dialog): don't assign aria-label to close button if button has text #11093
Conversation
| } | ||
|
|
||
| const buttonText = this._elementRef.nativeElement.innerText; | ||
| this._hasText = !!buttonText && buttonText.trim().length > 0; |
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.
A note on this: this could technically become inaccurate if the button has a data binding that starts off with a value, but then gets cleared. I decided not to handle that case, because of the potential performance implications.
| this.dialogRef = getClosestDialog(this._elementRef, this._dialog.openDialogs)!; | ||
| } | ||
|
|
||
| const buttonText = this._elementRef.nativeElement.innerText; |
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.
I had been thinking we could special-case mat-icon and ignore its text if it's present, but I realized we can actually just ignore the text if it's a mat-icon-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.
Done. I also reworded it a bit so it's more clear about what it does.
78bbb43 to
0ecd595
Compare
| const element = this._elementRef.nativeElement; | ||
|
|
||
| this._hasAriaLabel = element.hasAttribute('mat-icon-button') || | ||
| element.innerText.trim().length === 0; |
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.
Use textContent since it doesn't require a style calculation?
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.
Done.
0ecd595 to
9c53272
Compare
jelbourn
left a comment
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
|
@crisbeto In the check to determine if an Even if there is text content inside of the button, the user should be able to have screen readers read their own aria-label rather than button content. Something like this should work: this._hasAriaLabel = (
!buttonTextContent ||
buttonTextContent.trim().length === 0 ||
this.ariaLabel !== 'Close dialog'); |
|
@josephperrott that's what this line does. If the consumer specified an |
|
Correct, however I think currently the only paths to We need to cover the case where an |
9c53272 to
c99df8c
Compare
|
Ah I see. I've changed it to use the |
c99df8c to
a6323c9
Compare
a6323c9 to
54b0257
Compare
josephperrott
left a comment
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
54b0257 to
3e9f89c
Compare
|
Hey @crisbeto - looks like we've got a small problem on this PR. If the button has an aria-label, it is getting removed when there is button text. The flow is that |
3e9f89c to
15fec92
Compare
15fec92 to
8893005
Compare
|
Updated to avoid having the |
| <button class="close-without-text" mat-dialog-close></button> | ||
| <button class="close-icon-button" mat-icon-button mat-dialog-close>exit</button> | ||
| <button class="close-with-true" [mat-dialog-close]="true">Close and return true</button> | ||
| <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.
How do you think <button mat-dialog-close aria-label="foo">bar</button> should behave? It would be great to call this out. Is it possible the current implementation wipes out the aria-label? I'd propose that this is surprising.
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.
Also, might be worth evaluating <button mat-button-close [attr.aria-label]="'foo'">bar</button>. I think the current implementation also wipes foo out. This might be a fair bit less elegant to account for since Angular null attribute bindings clear an existing value and it's unidiomatic if not impossible to accept [attr.aria-label] as an input. However, behaving in an expected way should still be possible, either by checking if the static HTML attribute is set at constructor/init time, or some other creative way.
My 2c: If the template using mat-dialog-close specifies an explicit aria-label on that node using any conventional way, it should stick, regardless of the contents on the button.
No longer adds the `aria-label` to the `mat-dialog-close` directive, if the element that it's being applied to has text. This prevents the label from being read instead of the button text. Fixes angular#11084.
8893005 to
ffb4a79
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 longer adds the
aria-labelto themat-dialog-closedirective, if the element that it's being applied to has text. This prevents the label from being read instead of the button text.Fixes #11084.