fn
useCloseWatcher
v0.0.15testeddemoWrap 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
UseCloseWatcherReturn`isSupported`, `onClose`, `close`, and `destroy`