-
-
Notifications
You must be signed in to change notification settings - Fork 531
Description
Describe the bug
When the delayShow and delayHide props are set to 0, there is still a 66.68~83.35ms delay. At least 50ms of delay can be attributed to the debounce function wraping the handleShowTooltip and handleHideTooltip methods here:
react-tooltip/src/components/Tooltip/Tooltip.tsx
Lines 168 to 171 in 01c4a6f
| // debounce handler to prevent call twice when | |
| // mouse enter and focus events being triggered toggether | |
| const debouncedHandleShowTooltip = debounce(handleShowTooltip, 50) | |
| const debouncedHandleHideTooltip = debounce(handleHideTooltip, 50) |
Removing the call to debounce drops the delay to 16.67~33.34ms. The problem is that debounce is calling the functions on the trailing edge of the delay as opposed to the leading edge. The function also accepts an immediate argument, but with the the way that debounce is implemented here, passing true for immediate just disables the function call entirely.
react-tooltip/src/utils/debounce.ts
Lines 14 to 16 in 01c4a6f
| if (!immediate) { | |
| func.apply(this, args) | |
| } |
I recommend taking a look at underscore.js for how to implement debounce with the immediate param.
https://underscorejs.org/docs/modules/debounce.html
Version of Package
v5.10.5
To Reproduce
- Create an anchor that has a hover state (used to compare with tooltip delay).
- Add a tooltip with
0fordelayShowanddelayHide. - Observe delay on both show and hide.
Expected behavior
The hiding and showing of the tooltip should track with the hover state of the anchor.
Screenshots
With debounce:
tooltip_delay2.mp4
tooltip_delay_list.mp4
Without debounce: