zag icon indicating copy to clipboard operation
zag copied to clipboard

[Tooltip] after `disabled` goes true → false, the first hover does not open the tooltip

Open KhYossi opened this issue 1 month ago • 0 comments

🐛 Bug report

If a hover opened the tooltip and the pointer is still on the trigger when disabled becomes true, the first hover after disabled goes back to false does nothing. The second hover works. Keyboard focus is not affected.

A hover that opens the tooltip sets hasPointerMoveOpened, and only pointer.leave clears it. closeIfDisabled closes the tooltip but keeps the flag, and the trigger's onPointerLeave returns early while disabled, so the leave that would clear it is dropped. After re-enable, both closed → pointer.move branches are guarded by not("hasPointerMoveOpened"), so the first hover is ignored. The pointer.leave at the end of that hover clears the flag, which is why the second hover works.

Sources (main @ b44a5de):

The tooltip does not have to be open at the change. Escape or a pointer down closes it but keeps the flag too, so the same thing happens if the tooltip was closed that way and the pointer has not left since.

💥 Steps to reproduce

In the reproduction, D toggles disabled, so it can change while the pointer stays on the trigger (like a keyboard shortcut or a layout change in an app). A panel shows disabled, the machine state and context.hasPointerMoveOpened.

  1. Hover "Hover me" until the tooltip opens.
  2. Keep the pointer on the button and press D. The tooltip closes (disabled: true).
  3. Move the pointer off the button.
  4. Press D again (disabled: false).
  5. Hover the button. Nothing opens. hasPointerMoveOpened is still set.
  6. Move off and hover again. The tooltip opens.

Same result if Escape closes the tooltip in step 2 before D. Click Reset example before retrying.

💻 Link to reproduction

https://stackblitz.com/github/KhYossi/zag-tooltip-disabled-repro?file=src%2FApp.tsx

Source: https://github.com/KhYossi/zag-tooltip-disabled-repro

@zag-js/tooltip + @zag-js/react only, no Ark UI.

🧐 Expected behavior

After disabled goes back to false, the first hover opens the tooltip, the same as for a tooltip that was never disabled.

🧭 Possible Solution

Clear the flag when the disable closes the tooltip:

closeIfDisabled: ({ prop, send, context }) => {
  if (!prop("disabled")) return
  context.set("hasPointerMoveOpened", null)
  send({ type: "close", src: "disabled.change" })
},

The watch runs this action on every change to true, whatever the state, so it also covers the Escape / pointer-down case (there close is a no-op in closed, but the flag is still cleared). I patched this into 1.46.0 locally: with it, the first hover in step 5 opens the tooltip on both paths.

Alternatively, let onPointerLeave send pointer.leave while disabled. In closed, pointer.leave only runs clearPointerMoveOpened, so it cannot open anything.

🌍 System information

Software Version(s)
Zag Version @zag-js/tooltip 1.46.0, @zag-js/react 1.46.0. Also 1.43.1 through @ark-ui/react 5.38.2; same code on main
Browser Chromium 152
Operating System macOS 26.5

📝 Additional information

Use case: a side rail shows row tooltips only while it is collapsed to icons, with disabled={!collapsed}. A collapse or expand from the keyboard while the pointer rests on a row leaves that row's tooltip dead for one hover.

The same steps as a headless test (vitest + jsdom, through @ark-ui/react), if useful for a regression test:

const ui = (disabled: boolean) => (
  <Tooltip.Root openDelay={0} closeDelay={0} disabled={disabled}>
    <Tooltip.Trigger>Trigger</Tooltip.Trigger>
    <Tooltip.Positioner>
      <Tooltip.Content>Tip</Tooltip.Content>
    </Tooltip.Positioner>
  </Tooltip.Root>
)
const flush = () => act(() => new Promise((r) => setTimeout(r, 20)))
const { rerender } = render(ui(false))
const trigger = screen.getByRole("button")

fireEvent.pointerMove(trigger); await flush() // data-state "open"
rerender(ui(true)); await flush() // "closed", flag stays set
fireEvent.pointerLeave(trigger); await flush() // dropped: disabled
rerender(ui(false)); await flush() // "closed"
fireEvent.pointerMove(trigger); await flush() // "closed"  <- expected "open"
fireEvent.pointerLeave(trigger); await flush() // clears the flag
fireEvent.pointerMove(trigger); await flush() // "open"

KhYossi avatar Oct 22 '26 08:10 KhYossi