@hypothesis/frontend-shared
Version:
Shared components, styles and utilities for Hypothesis projects
21 lines (20 loc) • 997 B
TypeScript
/**
* @template T
* @typedef {import("preact/hooks").Ref<T>} Ref
*/
/**
* This hook provides a way to close or hide an element when a user interacts
* with elements outside of it or presses the Esc key. It can be used to
* create non-modal popups (eg. for menus, autocomplete lists and non-modal dialogs)
* that automatically close when appropriate.
*
* When the element is visible/open, this hook monitors for document interactions
* that should close it - such as clicks outside the element or Esc key presses.
* When such an interaction happens, the `handleClose` callback is invoked.
*
* @param {Ref<HTMLElement>} closeableEl - Outer DOM element for the popup
* @param {boolean} isOpen - Whether the popup is currently visible/open
* @param {() => void} handleClose - Callback invoked to close the popup
*/
export function useElementShouldClose(closeableEl: Ref<HTMLElement>, isOpen: boolean, handleClose: () => void): void;
export type Ref<T> = import("preact/hooks").Ref<T>;