-
-
Notifications
You must be signed in to change notification settings - Fork 536
Description
Describe the bug
This worked in v4 of the component.
I want to be able to create a Tooltip component dynamically per anchor only when the mouse enters the anchor, and destroy it when the mouse leaves it. I want to create it dynamically because every tooltip instance should support unique set of property values, so I cannot use just one shared instance. But I do not want to always create a tooltip instance when I create an anchor as it will have performance issues. I had the following logic that worked in v4 (this is my custom AnchorWithTooltip component):
render() {
<>
<div
onPointerEnter={() => {
this.setState({isShowing: true});
}}
onPointerLeave={() => {
this.setState({isShowing: false});
}}
data-tooltip-id={uniqueAnchorId}
>
{children}
</div>
{isShowing && (
<Tooltip
id={uniqueAnchorId}
content={this.getContent()}
>
</Tooltip>
)}
</>
}
What happens here is that when the mouse enters the anchor, the isShowing state property is set to true, so the Tooltip component renders. When the mouse leaves the anchor, the isShowing state property is set to false and the Tooltip component is unmounted.
When I looked at the code of the TooltipController, it looks like it does not recognize the pre-existing anchor associated with the Tooltip by id so the tooltip is not shown.
I realize that this is probably by design but I would really appreciate if you could make the necessary change to enable such behavior.
And thanks again for refactoring the component. It looks great.
Version of Package
latest
To Reproduce
See the explanation above
Expected behavior
See the explanation above
Desktop (please complete the following information if possible or delete this section):
- OS: [MacOS]
- Browser [all]
- Version [latest]
- Frameworks [React 18]