UNPKG

@base-ui-components/react

Version:

Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.

88 lines 3.11 kB
import { FloatingTreeStore } from "../components/FloatingTreeStore.js"; import type { ElementProps, FloatingContext, FloatingRootContext } from "../types.js"; type PressType = 'intentional' | 'sloppy'; export declare function normalizeProp(normalizable?: boolean | { escapeKey?: boolean; outsidePress?: boolean; }): { escapeKey: boolean; outsidePress: boolean; }; export interface UseDismissProps { /** * Whether the Hook is enabled, including all internal Effects and event * handlers. * @default true */ enabled?: boolean; /** * Whether to dismiss the floating element upon pressing the `esc` key. * @default true */ escapeKey?: boolean; /** * 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. * @default false */ referencePress?: boolean; /** * The type of event to use to determine a "press". * - `down` is `pointerdown` on mouse input, but special iOS-like touch handling on touch input. * - `up` is lazy on both mouse + touch input (equivalent to `click`). * @default 'down' */ referencePressEvent?: PressType; /** * Whether to dismiss the floating element upon pressing outside of the * floating element. * If you have another element, like a toast, that is rendered outside the * floating element's React tree and don't want the floating element to close * when pressing it, you can guard the check like so: * ```jsx * useDismiss(context, { * outsidePress: (event) => !event.target.closest('.toast'), * }); * ``` * @default true */ outsidePress?: boolean | ((event: MouseEvent | TouchEvent) => boolean); /** * The type of event to use to determine an outside "press". * - `intentional` requires the user to click outside intentionally, firing on `pointerup` for mouse, and requiring minimal `touchmove`s for touch. * - `sloppy` fires on `pointerdown` for mouse, while for touch it fires on `touchend` (within 1 second) or while scrolling away after `touchstart`. */ outsidePressEvent?: PressType | { mouse: PressType; touch: PressType; } | (() => PressType | { mouse: PressType; touch: PressType; }); /** * Whether to dismiss the floating element upon scrolling an overflow * ancestor. * @default false */ ancestorScroll?: boolean; /** * Determines whether event listeners bubble upwards through a tree of * floating elements. */ bubbles?: boolean | { escapeKey?: boolean; outsidePress?: boolean; }; /** * External FlatingTree to use when the one provided by context can't be used. */ externalTree?: FloatingTreeStore; } /** * Closes the floating element when a dismissal is requested — by default, when * the user presses the `escape` key or outside of the floating element. * @see https://floating-ui.com/docs/useDismiss */ export declare function useDismiss(context: FloatingRootContext | FloatingContext, props?: UseDismissProps): ElementProps; export {};