@leafygreen-ui/hooks
Version:
LeafyGreen UI Kit Custom Hooks
48 lines • 1.72 kB
TypeScript
interface UseBackdropClickOptions {
/**
* Whether the callback is enabled.
* It's recommended to set this to `false` when not in use,
* and toggle to `true` when the main elements (menu, tooltip, etc) are visible
*
* @default true
*/
enabled: boolean;
/**
* Allows the event to bubble up to other elements.
* When false, this ensures that only the `callback` is fired
* when the backdrop is clicked,
* (i.e. no other click event handlers are fired),
* and that the clicked element does not receive focus.
*
* To allow the event to propagate, set this to `true`,
* and ensure that you are correctly detecting whether the click target should receive focus,
* or whether focus should return to the popover trigger.
*
* @default false
*/
allowPropagation?: boolean;
}
/**
* Fires a callback when any element(s)
* _except_ those passed in as `foreground` is clicked.
*
* Note: Disable this hook (with the `enabled` arg)
* if the `foreground` element(s) are not in view (e.g. menu, tooltip, etc.).
*/
export declare function useBackdropClick(
/**
* Function called when any element
* _other than_ those provided is clicked.
*
* Callback is fired on the `click` event's capture phase,
* (i.e. before a click handler on the target element is fired)
*/
callback: Function,
/**
* The primary element(s) that are excluded from backdrop click
*/
foreground: React.RefObject<HTMLElement> | Array<React.RefObject<HTMLElement>>,
/** Additional options for the hook. See {@link UseBackdropClickOptions} */
options?: boolean | UseBackdropClickOptions): void;
export {};
//# sourceMappingURL=useBackdropClick.d.ts.map