question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom Position Tooltip Without React Child Doesn't work

See original GitHub issue

Hi!

Problem: (Disclaimer: This issue is probably my mistake) but I’ve been using Popper previously for modals and was thinking of having Popper’s Usage without a reference HTMLElement with Tippy that I came across Custom position section of the Tippy docs and I tried it with Tippy.js-React like this:

<Tippy
      content="Hello"
      onCreate={instance => {
        if (instance.popperInstance) {
          instance.popperInstance!.reference = {
            clientHeight: dimensions.height,
            clientWidth: dimensions.width,
            getBoundingClientRect: () => {
              return {
                left: rect.left,
                right: rect.right,
                top: rect.top,
                bottom: rect.bottom,
                height: rect.height,
                width: rect.width
              };
            }
          };
        }
      }}
    >
      <button>Hello</button>
    </Tippy>

It shows up but it is not in its position and it already has a child which is the <button></button>, probably I was expecting something like this:

    <Tippy
      content="Hello"
      onCreate={instance => {
        if (instance.popperInstance) {
          instance.popperInstance!.reference = {
            clientHeight: dimensions.height,
            clientWidth: dimensions.width,
            getBoundingClientRect: () => {
              return {
                left: rect.left,
                right: rect.right,
                top: rect.top,
                bottom: rect.bottom,
                height: rect.height,
                width: rect.width
              };
            }
          };
        }
      }}
    />

But Both Typescript and React don’t like it because they both expect the child in the TIppy Element.

Ways to reproduce: Mentioned in the problem section.

Issue Is there any way I can have Tippy without a React child and be positioned with costum position?

Thanks a lot in advance.

Edit: A word.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
atomikscommented, Mar 7, 2020

This should work fine in @tippyjs/react v4.0.0-alpha.1 (no dot, it’s a new package entirely), since it doesn’t require a child and you can use the getReferenceClientRect prop 😃

0reactions
ilyabocommented, Jan 25, 2021

Ah, sorry, found getReferenceClientRect now. This works great!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom Position Tooltip Without React Child Doesn't work #173
Hi! Problem: (Disclaimer: This issue is probably my mistake) but I've been using Popper previously for modals and was thinking of having ...
Read more >
Material UI tooltip doesn't display on custom component ...
Your Tooltip is not working properly because the child of a Material-UI Tooltip must be able to hold a ref. The following can...
Read more >
How To Make an Extremely Reusable Tooltip Component ...
Make it go above anything you want to show a tooltip on hover. It takes three props: content , which will be what's...
Read more >
Building a simple tooltip component that never goes off screen
How to build a simple, responsive and lightweight tooltip web component, with minimal HTML, CSS and JavaScript and no framework dependency.
Read more >
React Tooltip component - Material UI - MUI
Custom child element​​ The tooltip needs to apply DOM event listeners to its child element. If the child is a custom React element,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found