Skip to content

Commit

Permalink
[a11y] Fix: Media button on the page view grid does not have an acces…
Browse files Browse the repository at this point in the history
…sible name. (#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>
  • Loading branch information
5 people authored Dec 10, 2024
1 parent 788ceba commit 601ede4
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions packages/dataviews/src/dataviews-layouts/grid/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
FlexItem,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useInstanceId } from '@wordpress/compose';

/**
* Internal dependencies
Expand Down Expand Up @@ -66,6 +67,7 @@ function GridItem< Item >( {
const { showTitle = true, showMedia = true, showDescription = true } = view;
const hasBulkAction = useHasAPossibleBulkAction( actions, item );
const id = getItemId( item );
const instanceId = useInstanceId( GridItem );
const isSelected = selection.includes( id );
const renderedMediaField = mediaField?.render ? (
<mediaField.render item={ item } />
Expand All @@ -89,6 +91,23 @@ function GridItem< Item >( {
className: 'dataviews-view-grid__title-field dataviews-title-field',
} );

let mediaA11yProps;
let titleA11yProps;
if ( isItemClickable( item ) && onClickItem ) {
if ( renderedTitleField ) {
mediaA11yProps = {
'aria-labelledby': `dataviews-view-grid__title-field-${ instanceId }`,
};
titleA11yProps = {
id: `dataviews-view-grid__title-field-${ instanceId }`,
};
} else {
mediaA11yProps = {
'aria-label': __( 'Navigate to item' ),
};
}
}

return (
<VStack
spacing={ 0 }
Expand All @@ -112,7 +131,9 @@ function GridItem< Item >( {
} }
>
{ showMedia && renderedMediaField && (
<div { ...clickableMediaItemProps }>{ renderedMediaField }</div>
<div { ...clickableMediaItemProps } { ...mediaA11yProps }>
{ renderedMediaField }
</div>
) }
{ showMedia && renderedMediaField && (
<DataViewsSelectionCheckbox
Expand All @@ -128,7 +149,9 @@ function GridItem< Item >( {
justify="space-between"
className="dataviews-view-grid__title-actions"
>
<div { ...clickableTitleItemProps }>{ renderedTitleField }</div>
<div { ...clickableTitleItemProps } { ...titleA11yProps }>
{ renderedTitleField }
</div>
<ItemActions item={ item } actions={ actions } isCompact />
</HStack>
<VStack spacing={ 1 }>
Expand Down

1 comment on commit 601ede4

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in 601ede4.
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/12258766408
📝 Reported issues:

Please sign in to comment.