Skip to content

Commit

Permalink
Use Ariakit.Role
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Jan 16, 2024
1 parent 51abaf7 commit e66abe6
Showing 1 changed file with 6 additions and 29 deletions.
35 changes: 6 additions & 29 deletions packages/components/src/tooltip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
*/
// eslint-disable-next-line no-restricted-imports
import * as Ariakit from '@ariakit/react';
import classNames from 'classnames';

/**
* WordPress dependencies
*/
import { useInstanceId } from '@wordpress/compose';
import { Children, cloneElement } from '@wordpress/element';
import { Children } from '@wordpress/element';
import deprecated from '@wordpress/deprecated';

/**
Expand Down Expand Up @@ -104,33 +103,11 @@ function UnconnectedTooltip(
restProps,
'Tooltip'
);
const chainEvent =
( eventName: keyof typeof clonedProps ) =>
( ...args: unknown[] ): void => {
children.props[ eventName ]?.( ...args );
clonedProps[ eventName ]?.( ...args );
};
return isOnlyChild
? cloneElement( children, {
...clonedProps,
// Merge incoming classname with existing classname.
className: classNames(
children.props.className,
clonedProps.className
),
// Merge incoming inline styles with existing styles.
style: {
...children.props.style,
...clonedProps.style,
},
// Chain event listeners by calling both the existing and the
// incoming callback.
onClick: chainEvent( 'onClick' ),
onMouseEnter: chainEvent( 'onMouseEnter' ),
onBlur: chainEvent( 'onBlur' ),
ref,
} )
: children;
return isOnlyChild ? (
<Ariakit.Role { ...clonedProps } render={ children } />
) : (
children
);
}

return (
Expand Down

0 comments on commit e66abe6

Please sign in to comment.