Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/react/src/TooltipV2/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {Children, useEffect, useRef, useState, useMemo, type ForwardRefExoticComponent} from 'react'
import {useId, useProvidedRefOrCreate, useOnEscapePress} from '../hooks'
import React, {Children, useEffect, useState, useMemo, type ForwardRefExoticComponent, useRef} from 'react'
import {useId, useOnEscapePress, useMergedRefs} from '../hooks'
import {invariant} from '../utils/invariant'
import {warning} from '../utils/warning'
import {getAnchoredPosition} from '@primer/behaviors'
Expand Down Expand Up @@ -52,7 +52,7 @@ type TriggerPropsType = Pick<
| 'onTouchCancel'
| 'onTouchEnd'
> & {
ref?: React.RefObject<HTMLElement>
ref?: React.Ref<HTMLElement>
}

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

const [calculatedDirection, setCalculatedDirection] = useState<TooltipDirection>(direction)
Expand Down Expand Up @@ -284,8 +285,7 @@ export const Tooltip: ForwardRefExoticComponent<
<>
{React.isValidElement(child) &&
React.cloneElement(child as React.ReactElement<TriggerPropsType>, {
// @ts-expect-error it needs a non nullable ref
ref: triggerRef,
ref: mergedTriggerRef,
// If it is a type description, we use tooltip to describe the trigger
'aria-describedby': (() => {
// If tooltip is not a description type, keep the original aria-describedby
Expand Down
Loading