Used with a component · Dialog
useDialog
The headless modal behavior behind <Dialog>: a cancelable close, Escape through the shared layer stack, a Tab focus trap, scroll lock, initial focus and focus return, and optional back-button dismiss. It doesn't render an overlay or listen for outside clicks: call requestClose('outside', event) from your own overlay. <Dialog> adds the teleport, overlay, panel, title ids and animations. <Drawer> and <BottomSheet> are built on <Dialog>.
Install
import { useDialog } from 'vael-ui'Examples
<script setup lang="ts">
import { shallowRef, useTemplateRef } from 'vue'
import { useDialog } from 'vael-ui'
const open = shallowRef(false)
const panelEl = useTemplateRef<HTMLElement>('panel')
const wrapperEl = useTemplateRef<HTMLElement>('wrapper')
const { close, requestClose } = useDialog(open, { panelEl, wrapperEl })
</script>
<template>
<button @click="open = true">Edit profile</button>
<Teleport to="body">
<div v-if="open" ref="wrapper" class="wrapper">
<div class="overlay" @click="requestClose('outside', $event)" />
<div ref="panel" role="dialog" aria-modal="true" aria-label="Edit profile" tabindex="-1">
<input placeholder="Name" />
<button @click="close">Save</button>
</div>
</div>
</Teleport>
</template>