Skip to content

[BUG] The tooltip doesn't remain open, when target changes. #1053

Closed
@TomYeoman

Description

@TomYeoman

Bug description
When I create a new target for the tooltip, it's no longer automatically opened.

Version of Package
^5.16.1

To Reproduce

  1. Find an element in the page that is currently selected, and assign a random / static ID

const [tooltipId, setTooltipId] = useState("");

const anEventHandler= () => {
  
  const oldTargetElement = ....
  currentElement.removeAttribute("data-tooltip-id");
  currentElement.removeAttribute("data-tooltip-content");
  
  const newTargetElement = document.getElementById(`${targetClass}`);
  newTargetElement.setAttribute("data-tooltip-id", dataTooltipId);
  newTargetElement.setAttribute("data-tooltip-content", "Hi der");
  
  // This is a hook, and will trigger re-render
  setTooltipId(tooltipId);
}
  1. Render as normal
// In the render
<>
  <ReactTooltip id={tooltipId} place="bottom" isOpen={true} />
</>
  1. Repeat (1) as many times as you like, each time after initial render, you will have to hover over the element in order for the tooltip to open

Expected behavior

The current behavior is the tooltip only opens for the first element assigned the data attributes. For initial renders after that point I have to hover over the tooltip manually to open it again, I would like it to remain open (as per my code).

I have tried 2 approaches to fix this;

  1. Using a random ID when assigning tooltip to new element - This results in the OLD element having the tooltip on hover
  2. Using a static ID when assigning tooltip to new element - This results in the tooltip pointing to new element

In both cases however, I must still hover over the target element to open it.

Desktop (please complete the following information if possible or delete this section):
-Chrome, Windows 11

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions