Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] imperativeModeOnly not working as expected #1226

Open
gabrieljablonski opened this issue Sep 6, 2024 Discussed in #1225 · 1 comment
Open

[BUG] imperativeModeOnly not working as expected #1226

gabrieljablonski opened this issue Sep 6, 2024 Discussed in #1225 · 1 comment
Labels

Comments

@gabrieljablonski
Copy link
Member

gabrieljablonski commented Sep 6, 2024

Discussed in #1225

Originally posted by GabrielMAraujo September 6, 2024
Hi,

I've been trying to do a custom implementation of the tooltip that requires me to open and close the tooltip programmatically, and it also must not close the tooltip when the mouse hovers out the anchor div.

I read in the docs that the imperativeModeOnly prop should suffice in this case, but I tried to use it and it seems like it's not working.

I made an example in CodeSandbox that shows this behavior (it should open the tooltip and never close it): https://codesandbox.io/p/sandbox/tooltip-forked-gf82hl
Am I doing something wrong, or is this a bug?


Seems to be a bug with the imperativeModeOnly prop.

For now, manually clearing the events objects seems to work.

<Tooltip
  content="Hello world!"
  imperativeModeOnly={true}
  openEvents={{}}
  closeEvents={{}}
  globalCloseEvents={{}}
  ref={tooltipRef}
/>
@alsoknownasfoo
Copy link

I ran into a similar problem but I also have clickable=true because of the inclusion of buttons in the tooltip content. A workaround for me was settting an openEvents prop to true to prevent the tip from automatically dismissing on a mouseleave event.

openEvents={{
  dblclick: true,
}}

I believe the problem could be attributed to this code here:

if (clickable && !hasClickEvent) {
// used to keep the tooltip open when hovering content.
// not needed if using click events.
tooltipRef.current?.addEventListener('mouseenter', handleMouseEnterTooltip)
tooltipRef.current?.addEventListener('mouseleave', handleMouseLeaveTooltip)
}

Does the line need to consider imperative mode as well?

(clickable && !hasClickEvent && !imperativeModeOnly)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants