atomiks / tippyjs

Tooltip, popover, dropdown, and menu library
https://atomiks.github.io/tippyjs/
MIT License
11.91k stars 518 forks source link

Check for popperInstance before calling forceUpdate() #992

Closed mfal closed 2 years ago

mfal commented 2 years ago

Like the typings already hinting, the popperInstance can be null and thus should be checked before accessing it to avoid TypeErrors.

atomiks commented 2 years ago

The reason a check isn't needed there is because if the popper is queried on the DOM, that means it's showing and its popper instance is always available

mfal commented 2 years ago

I can provide you with an example. Maybe i'm doing something wrong...

mfal commented 2 years ago

You can try it here: https://codesandbox.io/s/pedantic-kalam-o9z4n

mfal commented 2 years ago

Might also fix #773?

atomiks commented 2 years ago

The working structure is:

      <Tippy singleton={source} render={(attrs, content) => <div {...attrs}>{content}</div>} />

      <Tippy
        singleton={target}
        content="First tooltip"
      >
        <button>First</button>
      </Tippy>

      <Tippy
        singleton={target}
        content="Second tooltip"
      >
        <button>Second</button>
      </Tippy>

The one in the CodeSandbox isn't the way singletons are used (or were tested at least)

mfal commented 2 years ago

Error is gone, but tooltips are not disappearing anymore. Any ideas on that issue? (See updated CodeSandbox)

atomiks commented 2 years ago

If you're using the render function, you likely want to be using Headless Tippy instead:

import Tippy, { useSingleton } from "@tippyjs/react/headless";

That's due to animations not being implemented with the default import, therefore the tippy doesn't unmount. You need to set animation={false} on the source singleton otherwise.

mfal commented 2 years ago

Many THX @atomiks 👏