A hook to merge or compose interaction event handlers together,
preserving memoization.
Interaction Hooks like useHover() and useFocus() do
two things: they create Effects inside themselves that work
independently, and also return event handlers intended to be
passed to the elements to add their functionality.
In your component API, the reference element may be external to
the component that useFloating() is called in (where the
positioning data is passed). In such a tree structure, the
interactions are shared between the reference element and
floating element in a “root” component higher than them — an
ancestor common to both.
An example would be:
To share the interactions between the reference and floating
elements, you can use the useFloatingRootContext() Hook:
It returns a context object
that is accepted by all interaction Hooks, similar to the one
returned by useFloating() — only without the positioning
data.
Pass the open state and elements to the Hook:
The root context must be available to useFloating() by
passing it as the rootContext option:
The Hook returns two core prop getters, one for the reference
element and one for the floating element. These prop getters
should be spread onto the elements:
All event handlers you pass in should be done so through the prop
getter, not the element itself:
This is because your handler may be either overwritten or
overwrite one of the Hooks’ handlers. More event handlers may
also be added in future versions.
A third prop getter is returned for item elements when dealing
with a list inside the floating element, which is not required
for all types of floating elements. See
useRole for more information on this prop
getter for listbox (e.g. select or combobox) or menu roles.