Alert Dialog
Ask for confirmation before an action continues.
Demos
Width
Usage
vue
<script setup lang="ts">
import { Accordion } from '~/components/ui/accordion'
const items = [
{ value: 'source', label: 'Do I own the source?', content: 'Yes. Copy and adapt the files.' },
]
</script>
<template>
<Accordion :items="items" />
</template>
Installation
Complete the shared installation. Copy AlertDialog.vue and index.ts into app/components/ui/alert-dialog/.
app/components/ui/alert-dialog/AlertDialog.vue
<script setup lang="ts">
import { AlertDialog as Primitive } from 'akaza-ui'
import { computed, useAttrs, useTemplateRef } from 'vue'
import { cn } from '../../../utils/ui'
import uiConfig from '../ui.config'
import {
alertDialogVariants,
resolveAlertDialogVariants,
type AlertDialogProps,
type AlertDialogSlots,
} from './index'
defineOptions({ inheritAttrs: false })
// Preserve Akaza defaults when optional props, including Boolean aliases, are omitted.
const props = withDefaults(defineProps<AlertDialogProps>(), {
as: undefined,
teleport: undefined,
transition: undefined,
duration: undefined,
title: undefined,
ariaLabel: undefined,
description: undefined,
ui: undefined,
modelValue: undefined,
})
defineSlots<AlertDialogSlots>()
const attrs = useAttrs()
const styles = computed(() => alertDialogVariants(resolveAlertDialogVariants(props, uiConfig)))
const mergedUi = computed(() => {
const overrides = props.ui as Record<string, string | undefined> | undefined
return Object.fromEntries(
Object.entries(styles.value).map(([part, style]) => [
part,
cn(style(), overrides?.[part], part === 'content' ? props.class : undefined),
]),
)
})
const primitiveProps = computed(() => {
const { class: _class, ui: _ui, width: _width, ...native } = props
return native
})
const primitive = useTemplateRef<InstanceType<typeof Primitive>>('primitive')
defineExpose({
get open() {
return primitive.value!.open
},
get close() {
return primitive.value!.close
},
get toggle() {
return primitive.value!.toggle
},
get titleId() {
return primitive.value!.titleId
},
get descriptionId() {
return primitive.value!.descriptionId
},
})
</script>
<template>
<component
:is="Primitive"
ref="primitive"
v-bind="{ ...primitiveProps, ...attrs }"
:ui="mergedUi"
>
<template v-for="(_, name) in $slots" #[name]="scope"
><slot :name="name as keyof AlertDialogSlots" v-bind="scope ?? {}"
/></template>
</component>
</template>
API
Variants and defaults
| Prop | Values | Default |
|---|---|---|
width | xs, sm, md, lg, xl | md |
width sets the floating surface width, independently of control size. The surface stays inside the viewport.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
title | string | — | Convenience title prop. Slot #title takes priority. |
ariaLabel | string | — | Fallback accessible name when no title is rendered. |
description | string | — | Convenience description prop. Slot #description takes priority. |
teleport | string | false | "body" | Teleport target for the dialog. |
transition | string | false | "akaza-alert-dialog" | Named Vue transition to apply. |
duration | number | 150 | Transition duration in ms. |
as | string | "div" | Root element tag. |
ui | AlertDialogUi | — | CSS class overrides. |
Slots
| Slot | Scoped props | Description |
|---|---|---|
trigger | { isOpen, open, close, toggle } | Element that opens the dialog. |
header | { close, titleId } | Header region. |
title | — | Dialog title. Defaults to the title prop. |
description | — | Description text. Defaults to the description prop. |
body | { close, descriptionId } | Main content area. |
footer | { close } | Action buttons region. |
Events
| Event | Payload | Description |
|---|---|---|
open-change | [open: boolean, details] | Fired when the open state changes. |
Exposed methods
| Method | Signature | Description |
|---|---|---|
open | (reason?, event?) => void | Opens the dialog. |
close | (reason?, event?) => void | Closes the dialog. |
toggle | (reason?, event?) => void | Toggles the dialog. |
titleId | string | Auto-generated id for the title element. |
descriptionId | string | Auto-generated id for the description element. |
Keyboard
| Key | Behavior |
|---|---|
Tab / Shift + Tab | Cycles through focusable controls inside open alert dialog. |
Escape | Does not close the alert dialog. The user must choose an action. |
Opening moves focus inside. Closing restores focus to previous element. Backdrop activation does not dismiss it.