From 7e649266e8aedd7d6c138f0821d382fa7e108a6c Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Fri, 6 Dec 2024 11:43:51 +0000 Subject: [PATCH] [a11y] Fix: Media button on the page view grid does not have an accessible name. --- .../src/dataviews-layouts/grid/index.tsx | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/dataviews/src/dataviews-layouts/grid/index.tsx b/packages/dataviews/src/dataviews-layouts/grid/index.tsx index 4e274c5b873fc..cd5ea0ef24b8e 100644 --- a/packages/dataviews/src/dataviews-layouts/grid/index.tsx +++ b/packages/dataviews/src/dataviews-layouts/grid/index.tsx @@ -15,6 +15,7 @@ import { FlexItem, } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; +import { useInstanceId } from '@wordpress/compose'; /** * Internal dependencies @@ -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 ? ( @@ -89,6 +91,21 @@ function GridItem< Item >( { className: 'dataviews-view-grid__title-field dataviews-title-field', } ); + let mediaA11yProps; + let titleA11yProps; + if ( isItemClickable( item ) && onClickItem ) { + mediaA11yProps = renderedTitleField + ? { + 'aria-labelledby': `dataviews-view-grid__title-field-${ instanceId }`, + } + : { + 'aria-label': __( 'Navigate to item' ), + }; + titleA11yProps = { + id: `dataviews-view-grid__title-field-${ instanceId }`, + }; + } + return ( ( { } } > { showMedia && renderedMediaField && ( -
{ renderedMediaField }
+
+ { renderedMediaField } +
) } { showMedia && renderedMediaField && ( ( { justify="space-between" className="dataviews-view-grid__title-actions" > -
{ renderedTitleField }
+
+ { renderedTitleField } +