fn

useCloseWatcher

v0.0.14testeddemo

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

UseCloseWatcherReturnisSupported, onClose, close, and destroy
PropertyTypeDescription
isSupportedReadonly<Ref<boolean>>Whether the native CloseWatcher API is available.
onClose(handler: CloseWatcherHandler) => VoidFunctionRegister a handler for close requests (Esc key / Android back / close()).
closeVoidFunctionRequest a close, firing every registered handler.
destroyVoidFunctionTear down the watcher and remove all registered handlers.