Skip to content

Commit 0f9ea0a

Browse files
andresdjassoclaude
andcommitted
fix(resource): keep the floating tooltip from jumping on click
Gate the focus-driven show behind :focus-visible so a mouse click (which focuses the trigger) no longer re-shows the tooltip anchored to the element's bottom edge. On click the tooltip now hides cleanly instead of jumping down; keyboard focus still shows it. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent a0587a7 commit 0f9ea0a

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

apps/sim/app/workspace/[workspaceId]/components/resource/components/floating-tooltip.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export function useFloatingTooltip(canShow: (target: HTMLElement) => boolean): {
118118
onFocus: (event) => {
119119
const target = event.currentTarget
120120
if (!canShowRef.current(target)) return
121+
if (!isFocusVisible(target)) return
121122
const rect = target.getBoundingClientRect()
122123
lastPointerRef.current = null
123124
setState({
@@ -194,6 +195,19 @@ export function clamp(value: number, min: number, max: number): number {
194195
return Math.max(min, Math.min(max, value))
195196
}
196197

198+
/**
199+
* Whether an element currently matches `:focus-visible` (keyboard focus, not focus produced by a
200+
* mouse click). Used to keep the tooltip from re-appearing/repositioning when the trigger is
201+
* clicked. Falls back to `true` where the selector can't be queried.
202+
*/
203+
export function isFocusVisible(element: Element): boolean {
204+
try {
205+
return element.matches(':focus-visible')
206+
} catch {
207+
return true
208+
}
209+
}
210+
197211
/**
198212
* Portaled tooltip body positioned from a {@link FloatingTooltipState}. Renders
199213
* nothing while hidden or during SSR.

0 commit comments

Comments
 (0)