@@ -44,14 +44,14 @@ const useTooltipEvents = ({
4444 tooltipShowDelayTimerRef,
4545 updateTooltipPosition,
4646} : {
47- activeAnchor : HTMLElement | null
48- anchorElements : HTMLElement [ ]
47+ activeAnchor : Element | null
48+ anchorElements : Element [ ]
4949 anchorSelector : string
5050 clickable : boolean
5151 closeEvents ?: AnchorCloseEvents
5252 delayHide : number
5353 delayShow : number
54- disableTooltip ?: ( anchorRef : HTMLElement | null ) => boolean
54+ disableTooltip ?: ( anchorRef : Element | null ) => boolean
5555 float : boolean
5656 globalCloseEvents ?: GlobalCloseEvents
5757 handleHideTooltipDelayed : ( delay ?: number ) => void
@@ -64,7 +64,7 @@ const useTooltipEvents = ({
6464 openEvents ?: AnchorOpenEvents
6565 openOnClick : boolean
6666 rendered : boolean
67- setActiveAnchor : ( anchor : HTMLElement | null ) => void
67+ setActiveAnchor : ( anchor : Element | null ) => void
6868 show : boolean
6969 tooltipHideDelayTimerRef : RefObject < NodeJS . Timeout | null >
7070 tooltipRef : RefObject < HTMLElement | null >
@@ -73,13 +73,13 @@ const useTooltipEvents = ({
7373} ) => {
7474 // Ref-stable debounced handlers — avoids recreating debounce instances on every effect run
7575 // eslint-disable-next-line @typescript-eslint/no-unused-vars
76- const debouncedShowRef = useRef ( debounce ( ( _anchor : HTMLElement | null ) => { } , 50 , true ) )
76+ const debouncedShowRef = useRef ( debounce ( ( _anchor : Element | null ) => { } , 50 , true ) )
7777 const debouncedHideRef = useRef ( debounce ( ( ) => { } , 50 , true ) )
7878
7979 // Cache scroll parents — only recompute when the element actually changes
8080 const anchorScrollParentRef = useRef < Element | null > ( null )
8181 const tooltipScrollParentRef = useRef < Element | null > ( null )
82- const prevAnchorRef = useRef < HTMLElement | null > ( null )
82+ const prevAnchorRef = useRef < Element | null > ( null )
8383 const prevTooltipRef = useRef < HTMLElement | null > ( null )
8484
8585 if ( activeAnchor !== prevAnchorRef . current ) {
@@ -187,10 +187,8 @@ const useTooltipEvents = ({
187187 updateTooltipPositionRef . current = updateTooltipPosition
188188
189189 // --- Handler refs (updated every render, read via ref indirection in effects) ---
190- const resolveAnchorElementRef = useRef < ( target : EventTarget | null ) => HTMLElement | null > (
191- ( ) => null ,
192- )
193- const handleShowTooltipRef = useRef < ( anchor : HTMLElement | null ) => void > ( ( ) => { } )
190+ const resolveAnchorElementRef = useRef < ( target : EventTarget | null ) => Element | null > ( ( ) => null )
191+ const handleShowTooltipRef = useRef < ( anchor : Element | null ) => void > ( ( ) => { } )
194192 const handleHideTooltipRef = useRef < ( ) => void > ( ( ) => { } )
195193
196194 const dataTooltipId = anchorSelector ? parseDataTooltipIdSelector ( anchorSelector ) : null
@@ -215,8 +213,8 @@ const useTooltipEvents = ({
215213 ? targetElement
216214 : targetElement . closest ( anchorSelector ) ) ?? null
217215
218- if ( matchedAnchor && ! disableTooltip ?.( matchedAnchor as HTMLElement ) ) {
219- return matchedAnchor as HTMLElement
216+ if ( matchedAnchor && ! disableTooltip ?.( matchedAnchor ) ) {
217+ return matchedAnchor
220218 }
221219 } catch {
222220 return null
@@ -230,7 +228,7 @@ const useTooltipEvents = ({
230228 )
231229 }
232230
233- handleShowTooltipRef . current = ( anchor : HTMLElement | null ) => {
231+ handleShowTooltipRef . current = ( anchor : Element | null ) => {
234232 if ( ! anchor ) {
235233 return
236234 }
@@ -283,7 +281,7 @@ const useTooltipEvents = ({
283281 // Update debounced callbacks to always delegate to latest handler refs
284282 const debouncedShow = debouncedShowRef . current
285283 const debouncedHide = debouncedHideRef . current
286- debouncedShow . setCallback ( ( anchor : HTMLElement | null ) => handleShowTooltipRef . current ( anchor ) )
284+ debouncedShow . setCallback ( ( anchor : Element | null ) => handleShowTooltipRef . current ( anchor ) )
287285 debouncedHide . setCallback ( ( ) => handleHideTooltipRef . current ( ) )
288286
289287 // --- Effect 1: Delegated anchor events + tooltip hover ---
@@ -302,9 +300,9 @@ const useTooltipEvents = ({
302300 }
303301
304302 const activeAnchorContainsTarget = ( event ?: Event ) : boolean =>
305- Boolean ( event ?. target && activeAnchorRef . current ?. contains ( event . target as HTMLElement ) )
303+ Boolean ( event ?. target instanceof Node && activeAnchorRef . current ?. contains ( event . target ) )
306304
307- const debouncedHandleShowTooltip = ( anchor : HTMLElement | null ) => {
305+ const debouncedHandleShowTooltip = ( anchor : Element | null ) => {
308306 debouncedHide . cancel ( )
309307 debouncedShow ( anchor )
310308 }
@@ -333,9 +331,9 @@ const useTooltipEvents = ({
333331 if ( ! targetAnchor && ! activeAnchorContainsTarget ( event ) ) {
334332 return
335333 }
336- const relatedTarget = ( event as MouseEvent ) . relatedTarget as HTMLElement | null
334+ const relatedTarget = ( event as MouseEvent ) . relatedTarget
337335 const containerAnchor = targetAnchor || activeAnchorRef . current
338- if ( containerAnchor ?. contains ( relatedTarget ) ) {
336+ if ( relatedTarget instanceof Node && containerAnchor ?. contains ( relatedTarget ) ) {
339337 return
340338 }
341339 debouncedHandleHideTooltip ( )
@@ -365,9 +363,9 @@ const useTooltipEvents = ({
365363 if ( ! targetAnchor && ! activeAnchorContainsTarget ( event ) ) {
366364 return
367365 }
368- const relatedTarget = ( event as FocusEvent ) . relatedTarget as HTMLElement | null
366+ const relatedTarget = ( event as FocusEvent ) . relatedTarget
369367 const containerAnchor = targetAnchor || activeAnchorRef . current
370- if ( containerAnchor ?. contains ( relatedTarget ) ) {
368+ if ( relatedTarget instanceof Node && containerAnchor ?. contains ( relatedTarget ) ) {
371369 return
372370 }
373371 debouncedHandleHideTooltip ( )
@@ -512,8 +510,8 @@ const useTooltipEvents = ({
512510 if ( ! showRef . current ) {
513511 return
514512 }
515- const target = ( event as MouseEvent ) . target as HTMLElement
516- if ( ! target ? .isConnected ) {
513+ const target = ( event as MouseEvent ) . target
514+ if ( ! ( target instanceof Node ) || ! target . isConnected ) {
517515 return
518516 }
519517 if ( tooltipRef . current ?. contains ( target ) ) {
0 commit comments