tippyjs-react icon indicating copy to clipboard operation
tippyjs-react copied to clipboard

Hide has a short delay even though `delay` prop set to 0

Open relogix opened this issue 3 years ago • 9 comments

I made a simple navbar by using Tippy. Then I realize the child items are hidden after a small period of time like it has a short delay (feel like 10-50 ms). I thought it was a default, then I try to set the delay to 0 and [0,0], but it still happens.. If I set delay to [500, 1000], it's not really that visible, but when I want to make it hidden directly, it has a short delay.

Can anyone tell me what;s going on? You can try it by make sandbox on Codesandbox.io, add @tippyjs/react, make a simple Tooltip, and you can feel there is a delay on hide.

relogix avatar Sep 06 '21 07:09 relogix

If delay is set to 0, tippy uses requestAnimationFrame to fire up instance.hide() event asynchronously. It might be possible that due to high CPU usage, the event might be delayed by the browser engine slightly.

I personally haven't experienced such delays with tippy, but it is pretty common in the JS world for setTimeout/requestAnimationFrame to run later than expected.

KubaJastrz avatar Sep 07 '21 18:09 KubaJastrz

Here's related code: https://github.com/atomiks/tippyjs/blob/0b10cfbf72d8db7932b371f24ff78d2ad140a0d5/src/createTippy.ts#L809-L821

KubaJastrz avatar Sep 07 '21 18:09 KubaJastrz

Have you tried mounting your tippys to a separate <div> container inside <body>, not <body> itself? There can be performance issues if you have a large number of nodes in the document.

atomiks avatar Oct 04 '21 09:10 atomiks

For anyone coming here using react-tippy based on the readme, to make hide delay as fast as possible when you want a show delay you can pass an array to delay like [showDelay, hideDelay] if you want them to be different.

This took me for a bit of a spin, as I'd assume that the default desired behavior for delay would only be to delay the showing. Anyway, hopefully this helps someone.

jessep avatar Nov 04 '21 19:11 jessep

@KubaJastrz There is definitely something strange going on: In this example notice when u hover out of [500, 0] it immediately closes it (no animation) and this is the desired outcome. Now on the same page, check out the example on [800,0]. Notice the sluggish exit animation even with 0ms close delay.

This is clearly a bug.

Pipe-Runner avatar Feb 15 '22 16:02 Pipe-Runner

@AakashMallik

What do you mean by "sluggish exit animation"? It looks smooth to me (windows 10, brave browser).

delay: 0 means that the animation starts roughly at 0ms after the mouse leave event, not that there is no animation (like in duration: 0).

KubaJastrz avatar Feb 15 '22 17:02 KubaJastrz

@AakashMallik

What do you mean by "sluggish exit animation"? It looks smooth to me (windows 10, brave browser).

delay: 0 means that the animation starts roughly at 0ms after the mouse leave event, not that there is no animation (like in duration: 0).

In that case, the two examples I have linked from the doc are inconsistent in behaviour. One animates out, while the other abruptly disappears. But I think u made the prop clear to me. I'll check what can be done from my end to get the desired result I am looking for.

Pipe-Runner avatar Feb 15 '22 19:02 Pipe-Runner

@KubaJastrz I just realized how dumb I am. I was comparing examples between delay and duration 😢 . Sorry to waste your time.

Pipe-Runner avatar Feb 15 '22 21:02 Pipe-Runner

For me, animation:false, fixed the issue

RokasDie avatar Sep 17 '23 15:09 RokasDie