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.
  • Loading branch information
jorgefilipecosta committed Dec 10, 2024
1 parent 101bbd2 commit 3b29077
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 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,17 @@ function GridItem< Item >( {
className: 'dataviews-view-grid__title-field dataviews-title-field',
} );

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

return (
<VStack
spacing={ 0 }
Expand All @@ -112,7 +125,9 @@ function GridItem< Item >( {
} }
>
{ showMedia && renderedMediaField && (
<div { ...clickableMediaItemProps }>{ renderedMediaField }</div>
<div { ...clickableMediaItemProps } { ...mediaA11yProps }>
{ renderedMediaField }
</div>
) }
{ showMedia && renderedMediaField && (
<DataViewsSelectionCheckbox
Expand All @@ -128,7 +143,16 @@ function GridItem< Item >( {
justify="space-between"
className="dataviews-view-grid__title-actions"
>
<div { ...clickableTitleItemProps }>{ renderedTitleField }</div>
<div
{ ...clickableTitleItemProps }
{ ...( isItemClickable( item ) && onClickItem
? {
id: `dataviews-view-grid__title-field-${ instanceId }`,
}
: {} ) }
>
{ renderedTitleField }
</div>
<ItemActions item={ item } actions={ actions } isCompact />
</HStack>
<VStack spacing={ 1 }>
Expand Down

0 comments on commit 3b29077

Please sign in to comment.