useDialog
useDialog(element, options) opens and closes a native <dialog> from the open model. Use it for your own modal window when Dialog does not fit.
show() opens the window, close(returnValue) closes it. Put the handlers from attrs on the <dialog>: they close the window on Escape and on a backdrop click. covered is true while another window is open on top.
Signature
useDialog: (element: DialogRef, options: DialogOptions) => DialogControlinterface DialogOptions { readonly open: Ref<boolean>; readonly closable?: MaybeRefOrGetter<boolean | undefined>; readonly closeOnBackdrop?: MaybeRefOrGetter<boolean | undefined>; readonly onClose?: ((returnValue: string) => void) | undefined;}interface DialogControl { readonly open: ComputedRef<boolean>; readonly covered: ComputedRef<boolean>; readonly returnValue: Readonly<Ref<string>>; readonly attrs: DialogAttrs; show(): void; close(returnValue?: string): void;}Usage
<template> <dialog ref="dialog" v-bind="control.attrs"> <form method="dialog">…</form> </dialog></template><script setup lang="ts">import { ref, useTemplateRef } from 'vue';import { useDialog } from '@numior/kit';const open = ref(false);const dialog = useTemplateRef<HTMLDialogElement>('dialog');const control = useDialog(dialog, { open, closeOnBackdrop: true, onClose: (value) => save(value) });</script>closable: false stops the window from closing on Escape and on a backdrop click. closeOnBackdrop: false turns off only the click.
While the window is open, the page under it does not scroll. After closing, focus returns to the button that opened the window. Dialog and Drawer are built on this composable.