-
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
[a11y] Fix: Media button on the page view grid does not have an accessible name. #67690
[a11y] Fix: Media button on the page view grid does not have an accessible name. #67690
Conversation
@@ -31,5 +35,7 @@ export default function getClickableItemProps< Item >( { | |||
onClickItem( item ); | |||
} | |||
}, | |||
...( id ? { id } : {} ), | |||
...( ariaLabelledby ? { 'aria-labelledby': ariaLabelledby } : {} ), |
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.
Why are we adding props and just returning them instead of just adding these props directly to the elements?
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.
Hi @youknowriad, because of a bad night of sleep, I guess 😅 I added the props directly to the elements.
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. |
1b5d556
to
f5b2ddd
Compare
<div { ...clickableMediaItemProps }>{ renderedMediaField }</div> | ||
<div | ||
{ ...clickableMediaItemProps } | ||
aria-labelledby={ `dataviews-view-grid__title-field-${ instanceId }` } |
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.
Should we add those if the element is not clickable and therefore interactive? 🤔
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.
Yes, as long as we have a role of button we should have a label. In cases where it is not interactive I think we should not have a role of button. But as far as I know in these cases the media button is always clickable, no?
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 we probably need to add a label in getClickableItemProps
or just make a check here?
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'm also curious why you chose aria-labelledby
instead of just 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.
I like using the title as a label, as it's the relevant information here. However, the titleField
is not mandatory and the consumer doesn't need to provide it (comment this line). In that case, what would be the backup?
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.
Hi @ntsekouras,
So we probably need to add a label in getClickableItemProps or just make a check here?
getClickableItemProps already prevented adding the role of button if the item was not clickable. However, we still added the aria-labelledby attribute even when the item was not clickable, and I have fixed that.
I'm also curious why you chose aria-labelledby instead of just label.
According to accessibility (a11y) guidelines, buttons should ideally be labeled using a visible label from their nested elements. If that's not possible, the next best solution is to use a visible label from an adjacent element and reference it. Only if neither option is available should we consider using an aria-label as a fallback. In this case, we can reference a visible adjacent element, so I opted for that approach.
This method was also technically simpler since the GridItem component does not have a way to compute the title as a simple string. Previously, we had a function called getItemTitle, but it seems that is no longer the case. By referencing the title field directly, I could simplify the implementation and avoid the need for additional props.
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.
Hi @oandregal,
I like using the title as a label, as it's the relevant information here. However, the titleField is not mandatory and the consumer doesn't need to provide it (comment this line). In that case, what would be the backup?
Good point I added a fallback for this case.
Related to this is that the media field doesn't communicate visually that is focused: Screen.Recording.2024-12-10.at.10.45.21.mov |
Another thing is that, unlike other buttons, pressing SPACE when the item is focused doesn't trigger a click even (it does work when pressing ENTER): Screen.Recording.2024-12-10.at.10.46.54.mov |
f5b2ddd
to
3b29077
Compare
@@ -89,6 +91,17 @@ function GridItem< Item >( { | |||
className: 'dataviews-view-grid__title-field dataviews-title-field', | |||
} ); | |||
|
|||
let mediaA11yProps = {}; | |||
if ( isItemClickable( item ) && onClickItem ) { |
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.
Can we extend this pattern to also calculate titleA11yProps
in this place rather than in the field below? That way things that are connected (aria-labelleby in media + id in title) are more obvious.
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.
Hi @oandregal, I applied the suggestion.
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.
We don't need id
in titleA11yProps
when the renderedTitleField
is null.
Hi @oandregal I fixed this issue at #67789. |
Hi @oandregal, I fixed the issue at #67791. |
3b29077
to
7e64926
Compare
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've left some little comment to address but this is ready, IMO.
Flaky tests detected in 1369e5f. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12256984439
|
…sible name. (WordPress#67690) Co-authored-by: jorgefilipecosta <jorgefilipecosta@git.wordpress.org> Co-authored-by: youknowriad <youknowriad@git.wordpress.org> Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org> Co-authored-by: oandregal <oandregal@git.wordpress.org>
All elements with an aria role of a button, such as the media item on the page's grid, should have a label, either nested inner text, an aria-label, or an aria-labeled by.
This PR fixes the issue by labeling the media field with the title field.
Testing
Navigate to ´wp-admin/site-editor.php?p=%2Fpage&layout=grid´.
With the developer tools inspect the media field (element with class dataviews-view-grid__media--clickable)
Go to the element a11y tab and verify the computed name for the element is correct.