Skip to content

Commit

Permalink
Tooltip: do not add the aria-describedby attribute to the anchor
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Oct 10, 2024
1 parent b06549d commit 51fd344
Showing 1 changed file with 1 addition and 23 deletions.
24 changes: 1 addition & 23 deletions packages/components/src/tooltip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import * as Ariakit from '@ariakit/react';
import { useStoreState } from '@ariakit/react';
import clsx from 'clsx';

/**
Expand All @@ -14,7 +13,6 @@ import {
useContext,
createContext,
forwardRef,
cloneElement,
} from '@wordpress/element';
import deprecated from '@wordpress/deprecated';

Expand Down Expand Up @@ -94,7 +92,6 @@ function UnforwardedTooltip(
placement: computedPlacement,
showTimeout: delay,
} );
const mounted = useStoreState( tooltipStore, 'mounted' );

if ( isNestedInTooltip ) {
return isOnlyChild ? (
Expand All @@ -104,31 +101,12 @@ function UnforwardedTooltip(
);
}

// TODO: this is a temporary workaround to minimize the effects of the
// Ariakit upgrade. Ariakit doesn't pass the `aria-describedby` prop to
// the tooltip anchor anymore since 0.4.0, so we need to add it manually.
// The `aria-describedby` attribute is added only if the anchor doesn't have
// one already, and if the tooltip text is not the same as the anchor's
// `aria-label`
// See: https://github.com/WordPress/gutenberg/pull/64066
// See: https://github.com/WordPress/gutenberg/pull/65989
function addDescribedById( element: React.ReactElement ) {
return describedById &&
mounted &&
element.props[ 'aria-describedby' ] === undefined &&
element.props[ 'aria-label' ] !== text
? cloneElement( element, { 'aria-describedby': describedById } )
: element;
}

return (
<TooltipInternalContext.Provider value={ CONTEXT_VALUE }>
<Ariakit.TooltipAnchor
onClick={ hideOnClick ? tooltipStore.hide : undefined }
store={ tooltipStore }
render={
isOnlyChild ? addDescribedById( children ) : undefined
}
render={ isOnlyChild ? children : undefined }
ref={ ref }
>
{ isOnlyChild ? undefined : children }
Expand Down

0 comments on commit 51fd344

Please sign in to comment.