One reference, multiple floating components?
See original GitHub issueWe 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:
- Created a year ago
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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.
same trouble when trying put Tooltip in Modal (both components got from the docs examples)