Provides the ability to apply CSS transitions to a floating
element, including correct handling of “placement-aware”
transitions.
There are two different Hooks you can use:
useTransitionStyles
is a high level wrapper around useTransitionStatus that
returns computed styles for you. This is simpler and can handle
the majority of use cases.
useTransitionStatus
is a low level hook that returns a status string to compute the
styles yourself.
This Hook provides computed inline styles that you can spread
into the style prop for a floating element.
This Hook is a standalone hook that accepts the
context object returned from useFloating():
isMounted is a boolean that determines whether or
not the floating element is mounted on the screen, which allows
for unmounting animations to play. This replaces the
open state variable.
styles is an object of inline transition styles
(React.CSSProperties).
The Hook defaults to a basic opacity fade transition with a
duration of 250ms.
When animating the floating element’s scale, it looks best if the
floating element’s transformOrigin is at the tip of the
arrow. The arrow middleware provides data to achieve this.
This Hook provides a status string that determines if
the floating element is in one of four states:
This Hook is a standalone hook that accepts the
context object returned from useFloating():
isMounted is a boolean that determines whether or
not the floating element is mounted on the screen, which allows
for unmounting animations to play. This replaces the
open state variable.
status is the status string (Status).
Above, we apply a data-status attribute to the
floating element. This can be used to target the transition
status in our CSS.
To define an opacity fade CSS transition:
transition-property: opacity is applied to all
states. This allows the transition to be interruptible.
The statuses map to the following:
'unmounted' indicates the element is unmounted from the
screen. No transitions or styles need to be applied in this
state.
'initial' indicates the initial styles of the floating
element as soon as it has been inserted into the DOM.
'open' indicates the floating element is in the open
state (1 frame after insertion) and begins transitioning in.
'close' indicates the floating element is in the close
state and begins transitioning out.
The transition duration must match the duration option
passed to the Hook.