Skip to content

Commit

Permalink
fix: Added aria labellelby and describedby
Browse files Browse the repository at this point in the history
  • Loading branch information
im3dabasia committed Feb 28, 2025
1 parent 5e7c286 commit 615a6dd
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions packages/components/src/menu-item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import type { ForwardedRef } from 'react';
import clsx from 'clsx';
import { v4 as uuidv4 } from 'uuid';

/**
* WordPress dependencies
Expand Down Expand Up @@ -32,18 +33,32 @@ function UnforwardedMenuItem(
isSelected,
role = 'menuitem',
suffix,
...buttonProps
...restProps
} = props;

className = clsx( 'components-menu-item__button', className );

const buttonProps = { ...restProps };
if ( info ) {
const labelId = `menu-item-label-${ uuidv4() }`;
const descriptionId = `menu-item-description-${ uuidv4() }`;

children = (
<span className="components-menu-item__info-wrapper">
<span className="components-menu-item__item">{ children }</span>
<span className="components-menu-item__info">{ info }</span>
<span id={ labelId } className="components-menu-item__item">
{ children }
</span>
<span className="components-menu-item__info" aria-hidden="true">
{ info }
</span>
<span id={ descriptionId } className="screen-reader-text">
{ info }
</span>
</span>
);

buttonProps[ 'aria-labelledby' ] = labelId;
buttonProps[ 'aria-describedby' ] = descriptionId;
}

if ( icon && typeof icon !== 'string' ) {
Expand Down

0 comments on commit 615a6dd

Please sign in to comment.