-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Adds aria-label to the search button, as accessibility enhancement #38136
Adds aria-label to the search button, as accessibility enhancement #38136
Conversation
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @Sisanu! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
I can see that before this PR, the Adding the a11y tag since this will need to be reviewed 👍 |
Thank you @aristath for the feedback! Anything is better than no accessibility for the button. |
I do not know if using a screen reader text or aria-label would be best. |
Maybe that's why |
I think you're only other option is VisuallyHidden from wordpress/components. Not sure this would actually be better than just a simple aria-label in this case. |
https://accessible360.com/accessible360-blog/use-aria-label-screen-reader-text/ Looks like screen reader text is a better option and I've always opted for using screen reader text anyway. For this, it really is trivial as both should have the same effect. @Sisanu I'll let you make the call on if you want to do the extra work with VisuallyHidden. |
Thank you @alexstine! I would keep it as simple as possible, and use just the |
72cc2bd
to
0ef7f75
Compare
I was giving this one last test when I realized the |
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 thought to add.
@@ -81,17 +82,19 @@ function render_block_core_search( $attributes ) { | |||
$button_internal_markup = wp_kses_post( $attributes['buttonText'] ); | |||
} | |||
} else { | |||
$aria_label = sprintf( 'aria-label="%s"', esc_attr( wp_strip_all_tags( $attributes['label'] ) ) ); |
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.
@ryelle I am not sure using aria-label in this context should be done. Honestly, I think this whole file should be refactored to include $attributes['button_aria_label']
that way users wouldn't be tempted to go out of their way to break accessibility. My problem with your approach is this.
$attributes['buttonText'] = '<span class="icon-class"></span>';
Now, the button is back to being inaccessible. Technically, it's not an icon button, but it still allows HTML right? Hints the need to strip tags for aria-label?
As I said, I would rather see an approach where accessibility related attributes are given and then we won't have to try to guess if users could make it inaccessible. Of course users can make it inaccessible, but the difference would be passing $attributes['buttonText']
vs. $attributes['button_aria_label']
.
Thoughts? Does this make sense?
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.
So, create a new attribute to pass in a button label? That does make sense, but I think it would be a good discussion to have in another issue. Overall I think getting this solution in place would improve things now, and it wouldn't prevent iterating on the label by introducing a new attribute.
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.
Sure, I'm good with that. I'll make a follow-up PR once this is in.
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.
Sounds good, though I'd suggest making an issue first - it'll need design input for the aria label setting UI.
Congratulations on your first merged pull request, @Sisanu! We'd like to credit you for your contribution in the post announcing the next WordPress release, but we can't find a WordPress.org profile associated with your GitHub account. When you have a moment, visit the following URL and click "link your GitHub account" under "GitHub Username" to link your accounts: https://profiles.wordpress.org/me/profile/edit/ And if you don't have a WordPress.org account, you can create one on this page: https://login.wordpress.org/register Kudos! |
Please note that there is an open trac ticket that can be closed once this is added to core https://core.trac.wordpress.org/ticket/55196 |
@Sisanu Thanks for tackling this! I also made an issue about the lack of label when I noticed it recently - #38647. Looking at your PR, it looks like the problem has now been solved for the front-end output of the block. In the editor there's some separate code for the search block's icon only button that's also missing a label: gutenberg/packages/block-library/src/search/edit.js Lines 255 to 263 in b44f513
Do you think a label should be added for this too? If so, is that something you'd be willing to work on? |
Hi @talldan! Sure, I can take a look. Please assign me the issue. |
@talldan, @alexstine, it's ready for review #38966 |
…38136) * Adds aria-label to the search button, as accessibility enhancement * Strip all tags for the aria label attribute * Add aria label only when the button is an icon Co-authored-by: Kelly Dwan <[email protected]>
Description
Adds aria-label to the search button, as accessibility enhancement.
How has this been tested?
Tested with Lighthouse and the accessibility score went up.
Screenshots
Types of changes
Enhancement
Checklist:
*.native.js
files for terms that need renaming or removal).