Skip to content

Commit 7b45d61

Browse files
authored
Just tooltip
1 parent a120837 commit 7b45d61

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

packages/react/src/TooltipV2/Tooltip.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import React, {Children, useEffect, useState, useMemo, type ForwardRefExoticComponent, useRef} from 'react'
2-
import {useId, useOnEscapePress, useIsMacOS, useMergedRefs} from '../hooks'
1+
import React, {Children, useEffect, useRef, useState, useMemo, type ForwardRefExoticComponent} from 'react'
2+
import {useId, useProvidedRefOrCreate, useOnEscapePress, useIsMacOS} from '../hooks'
33
import {invariant} from '../utils/invariant'
44
import {warning} from '../utils/warning'
55
import {getAnchoredPosition} from '@primer/behaviors'
@@ -50,7 +50,7 @@ type TriggerPropsType = Pick<
5050
| 'onTouchCancel'
5151
| 'onTouchEnd'
5252
> & {
53-
ref?: React.Ref<HTMLElement>
53+
ref?: React.RefObject<HTMLElement>
5454
}
5555

5656
// map tooltip direction to anchoredPosition props
@@ -126,8 +126,7 @@ export const Tooltip: ForwardRefExoticComponent<
126126
) => {
127127
const tooltipId = useId(id)
128128
const child = Children.only(children)
129-
const triggerRef = useRef<HTMLElement>(null)
130-
const mergedTriggerRef = useMergedRefs(triggerRef, forwardedRef)
129+
const triggerRef = useProvidedRefOrCreate(forwardedRef as React.RefObject<HTMLElement>)
131130
const tooltipElRef = useRef<HTMLDivElement>(null)
132131

133132
const [calculatedDirection, setCalculatedDirection] = useState<TooltipDirection>(direction)
@@ -285,7 +284,8 @@ export const Tooltip: ForwardRefExoticComponent<
285284
{React.isValidElement(child) &&
286285
// eslint-disable-next-line react-hooks/refs
287286
React.cloneElement(child as React.ReactElement<TriggerPropsType>, {
288-
ref: mergedTriggerRef,
287+
// @ts-expect-error it needs a non nullable ref
288+
ref: triggerRef,
289289
// If it is a type description, we use tooltip to describe the trigger
290290
'aria-describedby': (() => {
291291
// If tooltip is not a description type, keep the original aria-describedby

0 commit comments

Comments
 (0)