fn
useCloseWatcher
v0.0.14testeddemoWrap 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
| Parameter | Type | Description |
|---|---|---|
options? | UseCloseWatcherOptions | Configuration options |
Returns
UseCloseWatcherReturnisSupported, onClose, close, and destroy| Property | Type | Description |
|---|---|---|
isSupported | Readonly<Ref<boolean>> | Whether the native CloseWatcher API is available. |
onClose | (handler: CloseWatcherHandler) => VoidFunction | Register a handler for close requests (Esc key / Android back / close()). |
close | VoidFunction | Request a close, firing every registered handler. |
destroy | VoidFunction | Tear down the watcher and remove all registered handlers. |