R
fn

useCloseWatcher

v0.0.15testeddemo

Wrap the native `CloseWatcher` API to handle close requests (the `Esc` key or the Android back gesture). Falls back to listening for `Escape` keydown when `CloseWatcher` is unavailable. SSR-safe.

Examples

ts
const { onClose, close, isSupported } = useCloseWatcher();
onClose(() => { dialogOpen.value = false; });
ts
// Programmatically request a close
close();

Demo

Loading demo…

Signature

ts
export function useCloseWatcher(options: UseCloseWatcherOptions ={ ... }

Parameters

ParameterTypeDescription
options?UseCloseWatcherOptionsConfiguration options

Returns

UseCloseWatcherReturn`isSupported`, `onClose`, `close`, and `destroy`