Skip to content

Commit 82c28e8

Browse files
committed
fix(tooltip): don't seed pointer velocity from the trigger box on focus
The previous commit routed `onFocus` through a shared reveal helper that seeds `lastPointerRef` from the coordinates it is given. For focus those are the trigger's box center, not the pointer — so if the pointer already happened to be over the trigger, the next `pointermove` measured the box-to-cursor delta as velocity and spiked the skew/scale flourish. Split the helper in two: reveal-from-pointer seeds velocity tracking, reveal-from-element leaves it cleared. Restores the pre-PR behavior, where focus explicitly nulled the pointer snapshot. Caught by Cursor Bugbot.
1 parent fc4a679 commit 82c28e8

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

packages/emcn/src/components/tooltip/tooltip.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,28 @@ export function useFloatingTooltip(canShow: (target: HTMLElement) => boolean): {
119119
)
120120
}
121121

122-
const showNeutral = (clientX: number, clientY: number) => {
122+
/** Reveals the tooltip at the pointer, seeding velocity tracking from it. */
123+
const showFromPointer = (clientX: number, clientY: number) => {
123124
reset()
124125
lastPointerRef.current = { x: clientX, y: clientY, time: performance.now() }
125126
apply(clientX, clientY, NEUTRAL_MOTION)
126127
}
127128

129+
/**
130+
* Reveals the tooltip anchored to an element's box rather than the pointer.
131+
* Velocity tracking stays cleared: seeding it from the box would make the next
132+
* `pointermove` read the box-to-cursor delta as velocity and spike the flourish
133+
* when the pointer already happens to be over the trigger.
134+
*/
135+
const showFromElement = (clientX: number, clientY: number) => {
136+
reset()
137+
apply(clientX, clientY, NEUTRAL_MOTION)
138+
}
139+
128140
return {
129141
onPointerEnter: (event) => {
130142
if (!canShowRef.current(event.currentTarget)) return
131-
showNeutral(event.clientX, event.clientY)
143+
showFromPointer(event.clientX, event.clientY)
132144
},
133145
onPointerMove: (event) => {
134146
if (!canShowRef.current(event.currentTarget)) return
@@ -157,7 +169,7 @@ export function useFloatingTooltip(canShow: (target: HTMLElement) => boolean): {
157169
if (!canShowRef.current(target)) return
158170
if (!isFocusVisible(target)) return
159171
const rect = target.getBoundingClientRect()
160-
showNeutral(rect.left + rect.width / 2, rect.bottom)
172+
showFromElement(rect.left + rect.width / 2, rect.bottom)
161173
},
162174
onBlur: hide,
163175
}

0 commit comments

Comments
 (0)