Skip to content

Position Tooltip based on pointer position #967

Answered by gabrieljablonski
shmoeaz asked this question in Q&A
Discussion options

You must be logged in to vote

I'm not sure what you're trying to achieve since you weren't super specific, but here's an example using the click event and watching for the onClick event on the anchor.

function App() {
  const [position, setPosition] = React.useState({ x: 0, y: 0 });

  return (
    <div>
      <button
        data-tooltip-id="my-tooltip"
        data-tooltip-content={`I'm placed at (x:${position.x}, y:${position.y})`}
        onClick={(e) => {
          setPosition({
            x: e.clientX,
            y: e.clientY,
          });
        }}
      >
        Click me
      </button>
      <Tooltip id="my-tooltip" events={['click']} position={position} />
    </div>
  );
}

Using the hover event and wat…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by gabrieljablonski
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants