useDismiss
Closes the floating element when a dismissal is requested — by default, when the user presses the escape key or outside of the floating element with their pointer.
Usage
Options
enabled | Whether the Hook is enabled, including all internal Effects and event handlers. |
escapeKey | Whether to dismiss the floating element upon pressing the `esc` key. |
referencePress | Whether to dismiss the floating element upon pressing the reference element. You likely want to ensure the `move` option in the `useHover()` Hook has been disabled when this is in use. |
referencePressEvent | The type of event to use to determine a “press”. |
outsidePress | Whether to dismiss the floating element upon pressing outside of the floating element. |
outsidePressEvent | The type of event to use to determine an outside “press”. |
ancestorScroll | Whether to dismiss the floating element upon scrolling an overflow ancestor. |
bubbles | Determines whether event listeners bubble upwards through a tree of floating elements. |
capture | Determines whether to use capture phase event listeners. |
Reacting to dismissal
To react to the dismissal event, you can check for the reason string in the onOpenChange callback:
Compare
Compare to Floating UI React.