Skip to content

Dataviews: make the media item clickable as well #70985

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

Merged
merged 7 commits into from
Aug 1, 2025

Conversation

alshakero
Copy link
Contributor

@alshakero alshakero commented Jul 30, 2025

What?

This makes the media field part of the primary column behave the same way the title does when clicked. This makes sense because it's part of the primary column anyway.

Why?

More intuitive experience.

How?

By wrapping the media field with the same ItemClickWrapper that wraps the title field.

Testing Instructions

  1. Checkout this branch.
  2. Run npm run storybook:dev.
  3. Visit http://localhost:50240/?path=/docs/dataviews-dataviews--docs
  4. Click the thumbnail. An alert should show.

Testing Instructions for Keyboard

  1. Repeat the above steps.
  2. Instead of clicking, tab-nav until the thumbnail is in focus.
  3. Press "Enter".
  4. The alert should show.

Screenshots or screencast

Before

Screen.Recording.2025-07-30.at.16.53.24.mov

After

Screen.Recording.2025-07-30.at.16.51.27.mov

@alshakero alshakero marked this pull request as ready for review July 30, 2025 14:54
@alshakero alshakero requested a review from oandregal as a code owner July 30, 2025 14:54
Copy link

github-actions bot commented Jul 30, 2025

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: alshakero <[email protected]>
Co-authored-by: talldan <[email protected]>
Co-authored-by: oandregal <[email protected]>
Co-authored-by: youknowriad <[email protected]>
Co-authored-by: jameskoster <[email protected]>

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

@alshakero alshakero added [Type] Enhancement A suggestion for improvement. [Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond labels Jul 30, 2025
Comment on lines 46 to 51
<ItemClickWrapper
item={ item }
isItemClickable={ isItemClickable }
onClickItem={ onClickItem }
renderItemLink={ renderItemLink }
>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ends up as a button without a label, so there's an a11y problem to solve.

For the title field the title itself is used as the label, so you could probably match that - perhaps using aria-labelledby (https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-labelledby) and an id on the title.

Another option is to make the whole thumbnail and title wrapped in the clickable - but it might not feel right from a user point of view.

TBH, I'm also not convinced the item title is descriptive enough as a label, it doesn't really tell a screenreader user what onClickItem is going to do. Given dataviews is very abstract it could perform any kind of action. So another option is to add a way to pass a label in for an item, but that might be a separate story rather than trying to solve it in this PR. 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option is to make the whole thumbnail and title wrapped in the clickable - but it might not feel right from a user point of view.

Yeah, this is something I've heard a few times, the fact that the "primary column" is clickable is not very discoverable. This would require some design thinking, perhaps exploring making the media+title+description a card? Though, it'd add some weight that we may not want. Pinging @jameskoster @matt-west in case they have thoughts.

It'd also be nice to group media/title/description in a single unit from a keyboard navigation point of view. Otherwise, there's a stop for the media and there's another stop for the title (but they trigger the same action).

TBH, I'm also not convinced the item title is descriptive enough as a label, it doesn't really tell a screenreader user what onClickItem is going to do. Given dataviews is very abstract it could perform any kind of action.

Perhaps we could do with a generic label such as "Click item" for now.

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 not sure the description should be clickable. I think for now, adding the label (maybe a "Click Item %s") would be good enough.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems easier for now to make the title and thumbnail separate clickable elements, assuming we can find a good label for the thumbnail. We might consider a hover effect too; maybe the thumbnail border darkens slightly...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I went with Click item: <title> I added a colon to avoid all the grammatical issues in non-English languages, considering the item is an object and whatnot.

onClickItem={ onClickItem }
renderItemLink={ renderItemLink }
>
<div className="dataviews-view-table__cell-content-wrapper dataviews-column-primary__media">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we need this extra div? Can we pass the className to the ItemClickWrapper instead?

@alshakero
Copy link
Contributor Author

Thank you, everyone, for the reviews. I addressed all the feedback and rebased.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good to me. You might want to mention the change in the DataViews changelog.

onClickItem={ onClickItem }
renderItemLink={ renderItemLink }
className="dataviews-view-table__cell-content-wrapper dataviews-column-primary__media"
title={
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be title or aria-label?

@@ -16,6 +16,10 @@
- Support Ctrl + Click / Cmd + Click for multiselecting rows in the Table layout ([#70891](https://github.com/WordPress/gutenberg/pull/70891)).
- Add support for the `Edit` control on the date field type ([#70836](https://github.com/WordPress/gutenberg/pull/70836)).

### Enhancements

- Make the media item clickable along the title.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Make the media item clickable along the title.
- Make the media item clickable along the title. [#70985](https://github.com/WordPress/gutenberg/pull/70985)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, the pattern is so obvious.

@alshakero alshakero enabled auto-merge (squash) August 1, 2025 13:36
@alshakero alshakero merged commit 868b4b8 into trunk Aug 1, 2025
59 checks passed
@alshakero alshakero deleted the fix/media-item-clickable branch August 1, 2025 13:49
@github-actions github-actions bot added this to the Gutenberg 21.4 milestone Aug 1, 2025
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 [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants