-
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
Components: Split MenuItem
label and description for accessibility
#69372
base: trunk
Are you sure you want to change the base?
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Hey @afercia When you have a moment, could you please review my PR and share your thoughts on it? Thank you |
if ( info ) { | ||
const labelId = `menu-item-label-${ uuidv4() }`; | ||
const descriptionId = `menu-item-description-${ uuidv4() }`; |
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.
To generate unique IDs Gutenberg provides the useInstanceId
hook. See a simple example here, where you can pass 1) the component's name. 2) a string that will be used as prefix to the increasing number generated by useInstanceId
.
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 second to this, I understand that using uuid's would cause performance issues and would soon update the code to use instanceId
</span> | ||
<span id={ descriptionId } className="screen-reader-text"> | ||
{ info } | ||
</span> |
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 would move the info
span outside of the children markup entirely and use a hidden
html attribute instead of className="screen-reader-text"
. It can eveb be placed outside of the Item. This way the markup would be cleaner and there wouldn't be the need to use labelId
and aria-labelledby
because the labeling would simply use the content.
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 left some comments, please have a look.
The approach is good to me and it is similar to what I'm proposing for the Post Summary controls.
What?
Closes #58720
This PR updates the
MenuItem
component to properly separate its accessible name (children text) and accessible description (info text). Previously, both children and info were combined into the accessible name, leading to overly long and unclear labels for assistive technology users.Why?
The info text was incorrectly included in the accessible name, causing issues such as:
How?
Testing Instructions for Keyboard
Screenshots
|