Skip to content
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

Conversation

jorgefilipecosta
Copy link
Member

@jorgefilipecosta jorgefilipecosta commented Dec 6, 2024

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.

@jorgefilipecosta jorgefilipecosta added [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond labels Dec 6, 2024
@@ -31,5 +35,7 @@ export default function getClickableItemProps< Item >( {
onClickItem( item );
}
},
...( id ? { id } : {} ),
...( ariaLabelledby ? { 'aria-labelledby': ariaLabelledby } : {} ),
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link

github-actions bot commented Dec 6, 2024

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

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>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@jorgefilipecosta jorgefilipecosta force-pushed the fix/media-button-on-pages-grid-does-not-have-an-accessible-name branch from 1b5d556 to f5b2ddd Compare December 6, 2024 14:39
<div { ...clickableMediaItemProps }>{ renderedMediaField }</div>
<div
{ ...clickableMediaItemProps }
aria-labelledby={ `dataviews-view-grid__title-field-${ instanceId }` }
Copy link
Contributor

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? 🤔

Copy link
Member Author

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?

Copy link
Contributor

@ntsekouras ntsekouras Dec 10, 2024

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?

Copy link
Contributor

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.

Copy link
Member

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?

Screenshot 2024-12-10 at 11 01 49

Copy link
Member Author

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.

Copy link
Member Author

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.

@oandregal oandregal added the [Type] Bug An existing feature does not function as intended label Dec 10, 2024
@oandregal
Copy link
Member

oandregal commented Dec 10, 2024

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

@oandregal
Copy link
Member

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

@oandregal
Copy link
Member

Before After
Screenshot 2024-12-10 at 10 54 32 Screenshot 2024-12-10 at 10 56 48

@jorgefilipecosta jorgefilipecosta force-pushed the fix/media-button-on-pages-grid-does-not-have-an-accessible-name branch from f5b2ddd to 3b29077 Compare December 10, 2024 10:53
@@ -89,6 +91,17 @@ function GridItem< Item >( {
className: 'dataviews-view-grid__title-field dataviews-title-field',
} );

let mediaA11yProps = {};
if ( isItemClickable( item ) && onClickItem ) {
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

@jorgefilipecosta
Copy link
Member Author

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

Hi @oandregal I fixed this issue at #67789.

@jorgefilipecosta
Copy link
Member Author

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

Hi @oandregal, I fixed the issue at #67791.

@jorgefilipecosta
Copy link
Member Author

Before After
Screenshot 2024-12-10 at 10 54 32 Screenshot 2024-12-10 at 10 56 48

It seems to indicate the label is correctly computed 👍

@jorgefilipecosta jorgefilipecosta force-pushed the fix/media-button-on-pages-grid-does-not-have-an-accessible-name branch from 3b29077 to 7e64926 Compare December 10, 2024 12:46
Copy link
Member

@oandregal oandregal left a 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.

Copy link

Flaky tests detected in 1369e5f.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12256984439
📝 Reported issues:

@jorgefilipecosta jorgefilipecosta merged commit 601ede4 into trunk Dec 10, 2024
60 of 62 checks passed
@jorgefilipecosta jorgefilipecosta deleted the fix/media-button-on-pages-grid-does-not-have-an-accessible-name branch December 10, 2024 14:56
@github-actions github-actions bot added this to the Gutenberg 19.9 milestone Dec 10, 2024
yogeshbhutkar pushed a commit to yogeshbhutkar/gutenberg that referenced this pull request Dec 18, 2024
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants