Ada Lovelace
- Work email
- ada@analytical-engines.example
- Bio
- Writes the notes that turn the Analytical Engine from a calculator into a general-purpose machine. Currently documenting loops and conditional branching for the next release.
GhostDialog renders a modal or non-modal dialog overlay with accessible focus trapping, scroll locking, and background isolation. Import GhostDialog, GhostDialogTrigger, GhostDialogOverlay, GhostDialogContent, GhostDialogTitle, GhostDialogDescription, and GhostDialogClose from @ghostvue/vue for headless use, or from @ghostvue/themes for the default elevation-4 surface and scrim backdrop.
Profile card with an edit dialog: validated fields, a scrolling form on short screens, and real save and cancel outcomes.
Research engineer
<script setup lang="ts">
import { computed, nextTick, reactive, ref } from 'vue'
import {
GhostAvatar,
GhostButton,
GhostCard,
GhostDialog,
GhostDialogClose,
GhostDialogContent,
GhostDialogDescription,
GhostDialogOverlay,
GhostDialogTitle,
GhostDialogTrigger,
GhostField,
GhostFieldControl,
GhostFieldDescription,
GhostFieldError,
GhostFieldLabel,
GhostInput,
GhostTextarea,
} from '@ghostvue/themes'
interface Profile {
name: string
title: string
email: string
bio: string
}
/*
* Deterministic seed data. The saved profile only changes on a valid Save;
* the dialog edits a draft copy so Cancel, Escape, and a backdrop click all
* leave the card exactly as it was.
*/
const profile = reactive<Profile>({
name: 'Ada Lovelace',
title: 'Research engineer',
email: 'ada@analytical-engines.example',
bio: 'Writes the notes that turn the Analytical Engine from a calculator into a general-purpose machine. Currently documenting loops and conditional branching for the next release.',
})
const draft = reactive<Profile>({ ...profile })
const bioLimit = 280
const open = ref(false)
const status = ref('')
const submitted = ref(false)
const nameInvalid = computed(() => draft.name.trim() === '')
// A deliberately small check: the browser still runs native email validation.
const emailInvalid = computed(
() => !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(draft.email.trim()),
)
// Errors appear after the first Save attempt, then update as the user types.
const showNameError = computed(() => submitted.value && nameInvalid.value)
const showEmailError = computed(() => submitted.value && emailInvalid.value)
const dirty = computed(() =>
(Object.keys(profile) as (keyof Profile)[]).some(
(key) => profile[key] !== draft[key].trim(),
),
)
function setOpen(next: boolean): void {
if (next) {
// Every session starts from the saved profile, never a stale draft.
Object.assign(draft, profile)
submitted.value = false
status.value = ''
} else if (dirty.value) {
status.value = 'Edits discarded.'
}
open.value = next
}
async function save(event: SubmitEvent): Promise<void> {
submitted.value = true
if (nameInvalid.value || emailInvalid.value) {
// Keep the dialog open and move focus to the first field that needs work,
// once the errors have rendered and set aria-invalid.
const form = event.currentTarget
if (!(form instanceof HTMLFormElement)) return
await nextTick()
form.querySelector<HTMLElement>('[aria-invalid="true"]')?.focus()
return
}
const changed = dirty.value
Object.assign(profile, {
name: draft.name.trim(),
title: draft.title.trim(),
email: draft.email.trim(),
bio: draft.bio.trim(),
})
status.value = changed ? 'Profile saved.' : 'No changes to save.'
// Closing through state returns focus to the Edit profile trigger.
open.value = false
}
</script>
<template>
<GhostCard class="profile">
<template #header>
<div class="profile__header">
<GhostAvatar :name="profile.name" size="lg" />
<div class="profile__identity">
<h2 class="profile__name">{{ profile.name }}</h2>
<p class="profile__meta">{{ profile.title }}</p>
</div>
</div>
</template>
<dl class="profile__details">
<div class="profile__detail">
<dt>Work email</dt>
<dd>{{ profile.email }}</dd>
</div>
<div class="profile__detail">
<dt>Bio</dt>
<dd>{{ profile.bio }}</dd>
</div>
</dl>
<template #footer>
<div class="profile__actions">
<p class="profile__status" role="status">{{ status }}</p>
<GhostDialog :open="open" @update:open="setOpen">
<GhostDialogTrigger :as="GhostButton" variant="outline">
Edit profile
</GhostDialogTrigger>
<GhostDialogOverlay />
<GhostDialogContent>
<div class="profile-dialog__header">
<GhostDialogTitle>Edit profile</GhostDialogTitle>
<GhostDialogDescription>
Your name, title, and bio appear on shared reports and workspace
invitations.
</GhostDialogDescription>
</div>
<form
class="profile-dialog__form"
novalidate
@submit.prevent="save"
>
<div class="profile-dialog__row">
<GhostField required :invalid="showNameError">
<GhostFieldLabel required>Full name</GhostFieldLabel>
<GhostFieldControl v-slot="field">
<GhostInput
v-bind="field"
v-model="draft.name"
name="name"
autocomplete="name"
block
/>
</GhostFieldControl>
<GhostFieldError v-if="showNameError">
Enter your name.
</GhostFieldError>
</GhostField>
<GhostField>
<GhostFieldLabel>Job title</GhostFieldLabel>
<GhostFieldControl v-slot="field">
<GhostInput
v-bind="field"
v-model="draft.title"
name="title"
autocomplete="organization-title"
block
/>
</GhostFieldControl>
</GhostField>
</div>
<GhostField required :invalid="showEmailError">
<GhostFieldLabel required>Work email</GhostFieldLabel>
<GhostFieldDescription>
Sign-in links and report digests go here.
</GhostFieldDescription>
<GhostFieldControl v-slot="field">
<GhostInput
v-bind="field"
v-model="draft.email"
type="email"
name="email"
autocomplete="email"
block
/>
</GhostFieldControl>
<GhostFieldError v-if="showEmailError">
Enter an address like name@company.com.
</GhostFieldError>
</GhostField>
<GhostField>
<GhostFieldLabel>Bio</GhostFieldLabel>
<GhostFieldDescription>
{{ draft.bio.length }} of {{ bioLimit }} characters.
</GhostFieldDescription>
<GhostFieldControl v-slot="field">
<GhostTextarea
v-bind="field"
v-model="draft.bio"
name="bio"
:maxlength="bioLimit"
:rows="3"
:max-rows="6"
auto-resize
/>
</GhostFieldControl>
</GhostField>
<div class="profile-dialog__actions">
<GhostDialogClose
:as="GhostButton"
variant="soft"
tone="neutral"
>
Cancel
</GhostDialogClose>
<GhostButton type="submit">Save changes</GhostButton>
</div>
</form>
</GhostDialogContent>
</GhostDialog>
</div>
</template>
</GhostCard>
</template>
<style scoped>
/*
* The card owns its width: 32rem keeps the details at a readable measure and
* lets the card shrink with the preview on phones.
*/
.profile {
max-inline-size: 32rem;
}
.profile__header {
align-items: center;
display: flex;
gap: var(--ghost-space-gap-md);
min-inline-size: 0;
padding-block-end: var(--ghost-space-stack-sm);
}
.profile__identity {
display: grid;
gap: var(--ghost-space-gap-xs);
min-inline-size: 0;
}
/* Native text picks up docs prose styles, so each element resets its own. */
.profile__name {
color: var(--ghost-text-default);
font-size: var(--ghost-type-size-lg);
font-weight: var(--ghost-type-weight-semibold);
line-height: var(--ghost-type-line-tight);
margin: 0;
overflow-wrap: anywhere;
}
.profile__meta,
.profile__status {
color: var(--ghost-text-muted);
font-size: var(--ghost-type-size-sm);
line-height: var(--ghost-type-line-snug);
margin: 0;
}
.profile__details {
display: grid;
gap: var(--ghost-space-stack-sm);
margin: 0;
}
.profile__detail {
display: grid;
gap: var(--ghost-space-gap-xs);
}
.profile__detail dt {
color: var(--ghost-text-muted);
font-size: var(--ghost-type-size-xs);
font-weight: var(--ghost-type-weight-medium);
line-height: var(--ghost-type-line-snug);
}
.profile__detail dd {
color: var(--ghost-text-default);
font-size: var(--ghost-type-size-sm);
line-height: var(--ghost-type-line-normal);
margin: 0;
overflow-wrap: anywhere;
}
/* Give labels their own column when the preview has room for the values. */
@container ghost-demo (min-width: 26rem) {
.profile__detail {
align-items: baseline;
grid-template-columns: 5rem minmax(0, 1fr);
}
}
.profile__actions {
align-items: center;
display: flex;
flex-wrap: wrap;
gap: var(--ghost-space-gap-sm) var(--ghost-space-gap-md);
justify-content: flex-end;
}
.profile__status {
flex: 1 1 auto;
}
.profile-dialog__header {
display: grid;
gap: var(--ghost-space-gap-xs);
}
.profile-dialog__form {
display: grid;
gap: var(--ghost-space-stack-lg);
margin: 0;
}
/* Two names share a row when each can keep about 11rem; otherwise they stack. */
.profile-dialog__row {
display: grid;
gap: var(--ghost-space-stack-lg) var(--ghost-space-gap-md);
grid-template-columns: repeat(auto-fit, minmax(min(11rem, 100%), 1fr));
}
.profile-dialog__form :deep([data-part='description']),
.profile-dialog__form :deep([data-part='error']) {
overflow-wrap: anywhere;
}
.profile-dialog__actions {
display: flex;
flex-wrap: wrap;
gap: var(--ghost-space-gap-sm);
justify-content: flex-end;
}
</style>
The profile card opens an edit dialog that works on a draft copy. Save changes validates the name and email, writes the draft back to the card, and closes; focus returns to Edit profile. If a field is invalid, the dialog stays open and focus moves to the first field that needs attention. Cancel, Escape, and a backdrop click close without saving and the card stays as it was. Focus enters on the first field, the default when no initialFocus is set. The form keeps a 36rem width, the name row stacks when it gets narrow, and on short screens the whole dialog scrolls so the actions stay reachable.
While the modal is open, Tab stays inside, the background is inert, and body scroll is locked. The overlay and surface render through GhostPortal by default and unmount after their exit motion.
Release notes on the elevation-4 surface that scroll inside the dialog when taller than the viewport.
<script setup lang="ts">
import {
GhostButton,
GhostDialog,
GhostDialogClose,
GhostDialogContent,
GhostDialogDescription,
GhostDialogOverlay,
GhostDialogTitle,
GhostDialogTrigger,
} from '@ghostvue/themes'
// Deterministic release notes, long enough to overflow a phone viewport.
const changes = [
{
title: 'Shared reports',
body: 'Reports can be shared with a link that expires after 30 days. Owners can revoke a link at any time from the report menu.',
},
{
title: 'Faster search',
body: 'Workspace search now indexes comments and attachments, and returns the first results while the rest are still loading.',
},
{
title: 'Keyboard shortcuts',
body: 'Press ? anywhere to list every shortcut. Shortcuts follow your keyboard layout, including right-to-left layouts.',
},
{
title: 'Audit log export',
body: 'Admins can export up to 12 months of audit events as CSV. Large exports are prepared in the background and emailed when ready.',
},
{
title: 'Retired: legacy embeds',
body: 'Embeds created before version 3 stop rendering next month. Replace them with the new embed code from the share menu.',
},
] as const
</script>
<template>
<GhostDialog>
<GhostDialogTrigger :as="GhostButton" variant="outline">
What's new in 4.2
</GhostDialogTrigger>
<GhostDialogOverlay />
<GhostDialogContent class="notes-dialog">
<div class="notes-dialog__header">
<GhostDialogTitle>What's new in 4.2</GhostDialogTitle>
<GhostDialogDescription>
Five changes since the last release. The dialog scrolls when the notes
are taller than the viewport.
</GhostDialogDescription>
</div>
<ul class="notes-dialog__list">
<li v-for="change in changes" :key="change.title">
<h3 class="notes-dialog__item-title">{{ change.title }}</h3>
<p class="notes-dialog__item-body">{{ change.body }}</p>
</li>
</ul>
<div class="notes-dialog__actions">
<GhostDialogClose :as="GhostButton">Got it</GhostDialogClose>
</div>
</GhostDialogContent>
</GhostDialog>
</template>
<style scoped>
.notes-dialog__header {
display: grid;
gap: var(--ghost-space-gap-xs);
}
.notes-dialog__list {
display: grid;
gap: var(--ghost-space-stack-md);
list-style: none;
margin: 0;
padding: 0;
}
.notes-dialog__item-title {
color: var(--ghost-text-default);
font-size: var(--ghost-type-size-sm);
font-weight: var(--ghost-type-weight-semibold);
line-height: var(--ghost-type-line-snug);
margin: 0;
}
.notes-dialog__item-body {
color: var(--ghost-text-muted);
font-size: var(--ghost-type-size-sm);
line-height: var(--ghost-type-line-normal);
margin: 0;
}
.notes-dialog__actions {
display: flex;
justify-content: flex-end;
}
</style>
The themed surface caps its width and height to the viewport, minus the --ghost-space-inset-lg inset, and scrolls when the content is taller. It stays centered in both left-to-right and right-to-left documents.
Importing from @ghostvue/themes loads default.css, styling .ghost-dialog-overlay with var(--ghost-scrim) and .ghost-dialog-content with --ghost-elevation-4-*, border, hairline width, radius, inset padding, typography, and focus-ring --ghost-* tokens. Composing :as="GhostButton" delegates trigger and close styling cleanly.
A confirmation stacked on a share dialog; Escape dismisses only the innermost layer and focus returns to the outer dialog.
<script setup lang="ts">
import { ref } from 'vue'
import {
GhostButton,
GhostDialog,
GhostDialogClose,
type GhostDialogCloseExposed,
GhostDialogContent,
GhostDialogDescription,
GhostDialogOverlay,
GhostDialogTitle,
GhostDialogTrigger,
} from '@ghostvue/themes'
// The share link is local state, so revoking it is a visible, repeatable result.
const linkActive = ref(true)
const confirmOpen = ref(false)
const done = ref<GhostDialogCloseExposed | null>(null)
/*
* Revoking disables the inner dialog's opener, so focus cannot go back to it.
* Send it to Done instead; returning null keeps the default (the opener).
*/
function revokeReturnFocus(): HTMLElement | null {
return linkActive.value ? null : (done.value?.element ?? null)
}
function revoke(): void {
linkActive.value = false
confirmOpen.value = false
}
</script>
<template>
<GhostDialog>
<GhostDialogTrigger :as="GhostButton" variant="outline">
Share report
</GhostDialogTrigger>
<GhostDialogOverlay />
<GhostDialogContent>
<GhostDialogTitle>Share Q3 revenue report</GhostDialogTitle>
<GhostDialogDescription>
Pressing Escape while the confirmation is open closes only the inner
dialog.
</GhostDialogDescription>
<p class="share-status" role="status">
{{ linkActive ? 'Anyone with the link can view.' : 'Link revoked.' }}
</p>
<div class="share-actions">
<GhostDialog v-model:open="confirmOpen">
<GhostDialogTrigger
:as="GhostButton"
variant="soft"
tone="danger"
:disabled="!linkActive"
>
Revoke link
</GhostDialogTrigger>
<GhostDialogOverlay />
<GhostDialogContent
role="alertdialog"
:return-focus="revokeReturnFocus"
>
<GhostDialogTitle>Revoke the share link?</GhostDialogTitle>
<GhostDialogDescription>
People who open the old link will see an access request page.
</GhostDialogDescription>
<div class="share-actions">
<GhostDialogClose :as="GhostButton" variant="soft" tone="neutral">
Keep link
</GhostDialogClose>
<GhostButton tone="danger" @click="revoke">Revoke</GhostButton>
</div>
</GhostDialogContent>
</GhostDialog>
<GhostDialogClose ref="done" :as="GhostButton">Done</GhostDialogClose>
</div>
</GhostDialogContent>
</GhostDialog>
</template>
<style scoped>
.share-status {
color: var(--ghost-text-default);
font-size: var(--ghost-type-size-sm);
line-height: var(--ghost-type-line-snug);
margin: 0;
}
.share-actions {
display: flex;
flex-wrap: wrap;
gap: var(--ghost-space-gap-sm);
justify-content: flex-end;
}
</style>
Opening a dialog from inside another dialog stacks their dismissable layers, trapped focus scopes, inert sibling sets, and scroll locks cleanly. Pressing Escape dismisses only the innermost open dialog and restores focus and isolation back to the outer dialog.
Revoking the link disables the Revoke link button that opened the confirmation, so focus cannot return to it. The confirmation passes returnFocus to send focus to Done instead. While the link is active, returnFocus returns null and the default target is kept.
Destructive confirmation with role="alertdialog", outside-click dismissal disabled, and a status after confirming.
<script setup lang="ts">
import { ref } from 'vue'
import {
GhostButton,
GhostDialog,
GhostDialogClose,
GhostDialogContent,
GhostDialogDescription,
GhostDialogOverlay,
GhostDialogTitle,
GhostDialogTrigger,
} from '@ghostvue/themes'
const open = ref(false)
const deleted = ref(false)
function confirmDelete(): void {
deleted.value = true
open.value = false
}
</script>
<template>
<div class="alert-demo">
<GhostDialog v-model:open="open">
<GhostDialogTrigger :as="GhostButton" tone="danger" variant="outline">
Delete workspace
</GhostDialogTrigger>
<GhostDialogOverlay />
<GhostDialogContent role="alertdialog">
<GhostDialogTitle>Delete workspace permanently?</GhostDialogTitle>
<GhostDialogDescription>
This removes all projects and cannot be undone. Outside backdrop
clicks do not dismiss an alert dialog.
</GhostDialogDescription>
<div class="alert-demo__actions">
<GhostDialogClose :as="GhostButton" variant="soft" tone="neutral">
Cancel
</GhostDialogClose>
<GhostButton tone="danger" @click="confirmDelete">
Confirm delete
</GhostButton>
</div>
</GhostDialogContent>
</GhostDialog>
<p class="alert-demo__status" role="status">
{{ deleted ? 'Workspace deleted.' : '' }}
</p>
</div>
</template>
<style scoped>
.alert-demo {
align-items: center;
display: flex;
flex-wrap: wrap;
gap: var(--ghost-space-gap-sm) var(--ghost-space-gap-md);
}
.alert-demo__status {
color: var(--ghost-text-muted);
font-size: var(--ghost-type-size-sm);
line-height: var(--ghost-type-line-snug);
margin: 0;
}
.alert-demo__actions {
display: flex;
flex-wrap: wrap;
gap: var(--ghost-space-gap-sm);
justify-content: flex-end;
}
</style>
Passing role="alertdialog" on GhostDialogContent disables outside-click dismissal by default so destructive confirmations cannot be dismissed accidentally by clicking the backdrop, and emits a development warning (GHOST003) if no description is provided. The result is announced in a polite role="status" next to the trigger.
:modal="false" on GhostDialog to disable aria-modal, GhostDialogOverlay, scroll lock, background inert, and Tab trapping. Non-modal dialogs open at mount follow GhostPopover's openedAtMount rule so initial render does not steal focus on page load, whereas modal dialogs always move focus inside on open.v-model:open for controlled state, or omit open with defaultOpen for uncontrolled state.Unstyled modal dialog with overlay, trapped Tab focus, scroll lock, and inert background.
<script setup lang="ts">
import {
GhostDialog,
GhostDialogClose,
GhostDialogContent,
GhostDialogDescription,
GhostDialogOverlay,
GhostDialogTitle,
GhostDialogTrigger,
} from '@ghostvue/vue'
</script>
<template>
<GhostDialog>
<GhostDialogTrigger>Open dialog</GhostDialogTrigger>
<GhostDialogOverlay />
<GhostDialogContent>
<GhostDialogTitle>Account settings</GhostDialogTitle>
<GhostDialogDescription>
Update how session notifications appear while working.
</GhostDialogDescription>
<GhostDialogClose>Close</GhostDialogClose>
</GhostDialogContent>
</GhostDialog>
</template>
Import the same dialog parts from @ghostvue/vue when your application owns the scrim, surface, and focus styles. The modal still traps focus, isolates the background, and restores focus on close.
See the generated component references for props, emits, slots, exposed members, styling hooks, CSS variables, and executable examples.
| Prop | Type | Default | Description |
|---|---|---|---|
defaultOpen | boolean | false | Initial open state when open is omitted. |
modal | boolean | true | Enables modal behavior (trapped focus, scroll lock, inert background, overlay). |
open | boolean | — | Controlled open state. Omit for uncontrolled mode. |
| Slot | Slot props | Description |
|---|---|---|
default | close: () => void, open: boolean | Trigger, overlay, content, title, description, close parts, and optional custom UI reading the scoped state. |
@ghostvue/themes adds no props, events, or slots to the headless GhostDialog API, which it forwards.
GhostDialog (root) Emits update:open with (open: boolean). The default slot receives { open: boolean, close: () => void }.
GhostDialogTrigger Sets type="button" (when as="button"), aria-haspopup="dialog", aria-expanded, aria-controls, data-part="trigger", and data-state="open" | "closed". Exposes { element, focus, blur }.
GhostDialogOverlay Renders only when both open and modal are true. Sets aria-hidden="true", data-part="overlay", and data-state="open". Exposes { element, focus, blur }.
GhostDialogContent Sets role, aria-modal="true" (when modal=true), tabindex="-1", data-part="content", data-state="open", aria-labelledby (linking GhostDialogTitle), and aria-describedby (linking GhostDialogDescription). Exposes { element, focus, blur }.
Three optional props control focus entry and exit. Most dialogs never need them.
| Prop | Default | Behavior |
|---|---|---|
focusReady | true | While false, focus does not enter the dialog yet. Use it while content is still positioning or rendering. Once focus has entered, the trap stays on until close. |
initialFocus | undefined | Function returning the element to focus on entry. null or an invalid element keeps the default: [data-autofocus], then the first tabbable element. |
returnFocus | undefined | Function returning the element to focus on close. null, or a removed or disabled element, keeps the default: the element focused when the dialog opened. |
<GhostDialogContent
:focus-ready="positioned"
:initial-focus="() => selectedCell"
:return-focus="() => (triggerEnabled ? null : inputElement)"
>
...
</GhostDialogContent>Both functions run in the browser only, at the moment focus moves. They are never called during server rendering.
GhostDialogTitle Sets id and data-part="title", and registers as the dialog's accessible name unless aria-label or aria-labelledby is provided directly on GhostDialogContent. Exposes { element, focus, blur }.
GhostDialogDescription Sets id and data-part="description", and registers as the dialog's description (aria-describedby) on GhostDialogContent. Exposes { element, focus, blur }.
GhostDialogClose Closes the enclosing GhostDialog on click or keyboard activation and exposes { element, focus, blur }.
useGhostDialog(options?) Returns { isOpen, isModal, open, close, toggle, triggerId, contentId, titleId, descriptionId } for building custom dialog compositions over the same controllable state and deterministic IDs.
GhostDialogTitle (or pass aria-label / aria-labelledby on GhostDialogContent). Missing accessible names log GHOST002 in development. For role="alertdialog", also render GhostDialogDescription (or pass aria-describedby) to avoid GHOST003.aria-modal="true" with inert on background siblings (excluding [data-ghost-live] regions), ref-counted scroll locking, and looped Tab trapping.GhostPopover layers opened inside a modal dialog receive normal Tab navigation without focus pull-back, whereas inline popovers (:portal="false") keep Tab bounded inside the dialog.Escape, GhostDialogClose, overlay click, or controlled close restores focus to the trigger or previously focused element after background inert is cleared.