primitives: [Tooltip] Keep tooltip open when trigger is activated
Feature request
I’m trying to implement a tooltip that stays open when activating the trigger but couldn’t find any prop to control this. Something similar to the tooltip for reactions in slack.
Overview
Add a prop to the tooltip Root component which if set to true will keep the tooltip open even when the trigger is activated
Examples in other libraries
Chakra UI has closeOnClick prop https://chakra-ui.com/docs/overlay/tooltip#more-examples
About this issue
- Original URL
 - State: closed
 - Created 2 years ago
 - Reactions: 1
 - Comments: 30 (7 by maintainers)
 
I can contribute an example use case. 😃
Sometimes, we may have buttons or interactive components that copies a value when clicked. E.g. “click to copy URL”. In such a case, we may want the tooltip to remain open after clicking on it so that we can show the the value is indeed copied to the clipboard.
Just to make sure that the line reference won’t change https://github.com/radix-ui/primitives/blob/768bc53149aa1f432b5e630b99589237f6333364/packages/react/tooltip/src/Tooltip.stories.tsx#L617-L643
This has been addressed in #1290 and is now available in the latest rc: https://www.npmjs.com/package/@radix-ui/react-tooltip/v/0.1.8-rc.2
You can also see here an example of how to keep it open on activation thanks to the update: https://github.com/radix-ui/primitives/blob/main/packages/react/tooltip/src/Tooltip.stories.tsx#L588-L614
Yeah, and also dragging and the
:activestate on some browsers.I think relying on native
event.preventDefault()is an anti-pattern, not only because of what @jjenzz said. But also because users will rely on implementation details. What if the library starts doing the action in theonPointerDownevent instead ofonMouseDownin the future?Exposing props like the suggested
closeOnClickis a better solution in my opinion.Please share example code
Yeah if I put my “feel” aside and think pragmatically, I think you’re right, basically anything that is “dismissable” by design should dismiss just itself.
Yeah that’s all great points. We discussed this many times actually but for some reason I didn’t think of it this time, so yeah perhaps we should add a custom event or something like that.
We usually expose
CustomEvents likeonDismiss/onClosethat consumers canevent.preventDefault()to avoid reliance on implementation detail and unexpected side effects.There are often custom side effects/an alternate behaviour people want to implement when preventing ours so the event approach gives them the opportunity to do both all in one prop (reduces API surface).
In the tooltip case, it isn’t likely that they need to action something else as part of that event but would be good to keep our APIs consistent.
Ah sorry, my bad it looks like we have an
onMouseDowntoo, so if you do the same inonMouseDownit should work.