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.

One reference, multiple floating components?

See original GitHub issue

We want a button with these behaviors:

  • on hover, displays its title in a tooltip;
  • on click, opens an action menu.

So the button is a singular reference, triggered two different floating components – a tooltip and a drop-down menu – on its hover and click events, respectively.

Is this possible? Is there a best practice for this? Here’s what I’m thinking – in React – but I’m also wondering whether there’s a more efficient way to do this:

const {
  context: hoverContext,
  floating: hoverFloating,
  reference: hoverReference,
} = useFloating({ ...hoverConfig });

const {
  getFloatingProps: hoverGetFloatingProps,
  getReferenceProps: hoverGetReferenceProps,
} = useInteractions([
  useHover(hoverContext),
]);

const {
  context: clickContext,
  floating: clickFloating,
  reference: clickReference,
} = useFloating({ ...clickConfig });

const {
  getFloatingProps: clickGetFloatingProps,
  getReferenceProps: clickGetReferenceProps,
} = useInteractions([
  useClick(clickContext),
  useDismiss(clickContext)
]);

return (
  <div {...hoverGetReferenceProps}>
    <button {...clickGetReferenceProps}>Title</button>
  </div>

  <Portal>
    <div {...hoverGetFloatingProps}> ... </div>
    <div {...clickGetFloatingProps}> ... </div>
  </Portal>
);

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
atomikscommented, Sep 15, 2022

@EvHaus It’s because you aren’t forwarding all the props that the Menu passes to the Tooltip component into the prop getter. Since it clones its child element, which for the Menu is the Tooltip, those props need to be forwarded down.

You may also need to merge the children.props with them.

Screen Shot 2022-09-15 at 3 02 14 pm
1reaction
S-Ladroscommented, Sep 15, 2022

same trouble when trying put Tooltip in Modal (both components got from the docs examples)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Stacking with floated blocks - CSS: Cascading Style Sheets
Floating elements are placed between non-positioned elements and positioned elements: The background and borders of the root element. Descendant ...
Read more >
React
Multiple floating elements on a single reference element​​ Merge the reference refs on the element for each useFloating() , and call the getReferenceProps()...
Read more >
CSS: Floating multiple elements with different heights on ...
Then we set it to have a "template" for columns of 2 equal width columns (1 "fractional unit"), and gaps between columns as...
Read more >
Multiple cards in floating arrangement
I like the look of the cards in the Angular Card Component page, but I'm having issues making simple cards that match any...
Read more >
Getting started with Floating UI
Floating elements are elements that “float” on top of the UI without ... for inline reference elements that span over multiple lines, ...
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