Skip to content

Commit

Permalink
Simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Sep 5, 2022
1 parent 47bc39f commit 16d345e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/components/src/tooltip/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
concatChildren,
useEffect,
useState,
useCallback,
} from '@wordpress/element';
import { useDebounce, useMergeRefs } from '@wordpress/compose';

Expand Down Expand Up @@ -131,11 +130,11 @@ function Tooltip( props ) {
// Create a reference to the Tooltip's child, to be passed to the Popover
// so that the Tooltip can be correctly positioned. Also, merge with the
// existing ref for the first child, so that its ref is preserved.
const childRef = useCallback( ( node ) => {
setPopoverAnchor( node ?? undefined );
}, [] );
const existingChildRef = Children.toArray( children )[ 0 ]?.ref;
const mergedChildRefs = useMergeRefs( [ childRef, existingChildRef ] );
const mergedChildRefs = useMergeRefs( [
setPopoverAnchor,
existingChildRef,
] );

const createMouseDown = ( event ) => {
// In firefox, the mouse down event is also fired when the select
Expand Down Expand Up @@ -258,7 +257,8 @@ function Tooltip( props ) {
: getRegularElement;

const popoverData = {
anchor: popoverAnchor,
// `anchor` should never be `null`
anchor: popoverAnchor ?? undefined,
isOver,
offset: 4,
position,
Expand Down

0 comments on commit 16d345e

Please sign in to comment.