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

[preact/compat] @radix-ui/react-tooltip immediately hide tooltip after hover on element #3805

Open
1 task
glook opened this issue Nov 18, 2022 · 5 comments
Open
1 task
Labels

Comments

@glook
Copy link

glook commented Nov 18, 2022

  • Check if updating to the latest Preact version resolves the issue

Describe the bug
Radix tooltips immediately closing after hover on element

CleanShot 2022-11-18 at 16 34 03@2x

CleanShot 2022-11-18 at 16 37 17

To Reproduce

https://codesandbox.io/s/preact-radix-ui-react-tooltip-issue-lshsmd?file=/src/App.tsx

Steps to reproduce the behavior:

  1. Hover on button
  2. You will see that tooltip will be visible for just a moment

Expected behavior
Expected that tooltip will be visible all time when cursor is hover button

nikogoli added a commit to nikogoli/testing-shadcn-ui-in-fresh that referenced this issue Nov 2, 2023
hover 状態でも tooltip の表示が永続化されず、表示後即座に消えてしまう ([issue](preactjs/preact#3805))
nikogoli added a commit to nikogoli/testing-shadcn-ui-in-fresh that referenced this issue Nov 2, 2023
hover 状態でも tooltip の表示が永続化されず、表示後即座に消えてしまう ([issue](preactjs/preact#3805))
nikogoli added a commit to nikogoli/testing-shadcn-ui-in-fresh that referenced this issue Nov 2, 2023
hover 状態でも tooltip の表示が永続化されず、表示後即座に消えてしまう
([issue](preactjs/preact#3805))
@iPavlikov

This comment was marked as off-topic.

@wolfflow

This comment was marked as off-topic.

@nikogoli
Copy link

I found a solution. It does not "solve" the problem, but works anyway.

https://codesandbox.io/s/preact-radix-ui-react-tooltip-issue-forked-kys9rl?file=/src/tooltipDemo.tsx

Just import useState and create a boolean-state and its stateUpdater, and pass them as open and onOpenChange properties of <Tooltip.Root>.

2024-08-13-000134

I found this technique in the code of shadcn/ui's Collapsible-demo.

@JoviDeCroock
Copy link
Member

@nikogoli Very interesting find, I really wonder if it's some kind of double event firing/... but it stands out that if other libraries are running into it that it might not be isolated to preact 😅

@JoviDeCroock
Copy link
Member

JoviDeCroock commented Nov 22, 2024

I am actually quite unsure of how this even works in React, the steps are the following

This kind of relies on the Tooltip being rendered after the document finishes the processing of the event. As the DOM interleaves microticks between bubbling this isn't a set time so the node could have mounted or not yet 😅 in the core of Preact we handle this with an event-clock so an event that's newer than its listener won't fire a callback. These are custom events and maybe the React event delegation handles that similarly 😅

This issue should probably be fixed on the radix side where it can't close the newly opened popup immediately, event-delegation executes all these events synchronously but that's not really how browser events work.

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

5 participants