@@ -2,7 +2,7 @@ import React from 'react'
22import { useSSRSafeId } from '@react-aria/ssr'
33import type { AnchorPosition , AnchorSide , AnchorAlignment } from '@primer/behaviors'
44import Box from '../Box'
5- import { useAnchoredPosition , useProvidedRefOrCreate } from '../hooks'
5+ import { useAnchoredPosition } from '../hooks'
66import { SxProp , merge , BetterSystemStyleObject } from '../sx'
77
88type TooltipDirection = 'nw' | 'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w'
@@ -21,7 +21,7 @@ export type TooltipProps = {
2121 /** Use aria-describedby or aria-labelledby */
2222 type ?: 'description' | 'label'
2323 /** Tooltip target */
24- children : React . ReactElement & { ref ?: React . RefObject < HTMLElement > }
24+ children : React . ReactElement
2525 /** When set to true, tooltip appears without any delay */
2626 noDelay ?: boolean
2727 /** @deprecated Always set to true now. */
@@ -55,16 +55,8 @@ export const Tooltip: React.FC<TooltipProps> = ({
5555 sx = { } ,
5656 ...props
5757} ) => {
58- const tooltipId = useSSRSafeId ( )
59-
60- const childRef = children . ref
61- const anchorElementRef = useProvidedRefOrCreate ( childRef )
6258 const tooltipRef = React . useRef < HTMLDivElement > ( null )
63-
64- const child = React . cloneElement ( children , {
65- ref : anchorElementRef ,
66- [ type === 'description' ? 'aria-describedby' : 'aria-labelledby' ] : tooltipId
67- } )
59+ const anchorElementRef = React . useRef < HTMLElement > ( null )
6860
6961 const { position} = useAnchoredPosition ( {
7062 side : directionToPosition [ direction ] . side ,
@@ -74,6 +66,13 @@ export const Tooltip: React.FC<TooltipProps> = ({
7466 anchorElementRef
7567 } )
7668
69+ const tooltipId = useSSRSafeId ( )
70+
71+ const child = React . cloneElement ( children , {
72+ ref : anchorElementRef ,
73+ [ type === 'description' ? 'aria-describedby' : 'aria-labelledby' ] : tooltipId
74+ } )
75+
7776 const tooltipText = text || props [ 'aria-label' ]
7877
7978 return (
0 commit comments