GhostDrawer specification
Status: Approved. Approved by Zac (maintainer) in chat, November 17, 2026 — see GHO-91 Linear document (GHO-91 — Drawer / Sheet design plan and specification). Direction (Option A) approved by Zac in chat on the same date. Predecessors: GhostDialog specification (GHO-28) and ADR 0012: Modal overlays.
Purpose and user problems
GhostDrawer (also called a Sheet) is an edge-anchored modal or non-modal overlay panel anchored to the start, end, top, or bottom viewport edge. It serves secondary workflows such as DataTable filter panels, row-detail inspectors, navigation drawers, and multi-field creation flows that benefit from full viewport height or width without leaving the current page.
It is a Dialog variant: it follows the same APG Dialog (Modal) contract and reuses the exact focus, dismissal, scroll-lock, and background-isolation mechanics as GhostDialog through an internal shared module.
Non-goals
- Touch swipe / drag-to-dismiss gestures or multi-stop snap points (deferred by the approved Option A direction).
- JavaScript exit orchestration. Exit motion is CSS-only and owned by the presence lifecycle, matching
GhostDialog. - Anchored floating callouts positioned relative to a trigger (
GhostPopoveranduseFloatingown anchored positioning). - Persistent in-flow split-pane sidebars that are not dialogs.
Public API
Parts and exports
Headless exports from @ghostvue/vue:
GhostDrawer(root state and context provider; renderless)GhostDrawerTrigger(control that opens/toggles the drawer)GhostDrawerOverlay(modal backdrop rendered whileopenandmodal=true)GhostDrawerContent(edge-anchoreddialogoralertdialogsurface)GhostDrawerTitle(h2heading linked viaaria-labelledby)GhostDrawerDescription(pdescription linked viaaria-describedby)GhostDrawerClose(close control inside drawer content)useGhostDrawer(composable returning reactive open/modal/side/dir state, controls, and deterministic part IDs)resolveDrawerDir(pure SSR-safe helper resolving'ltr' | 'rtl')- Types:
GhostDrawerSide,GhostDrawerDirection,GhostDrawerProps,GhostDrawerSlotProps,GhostDrawerTriggerElement,GhostDrawerTriggerProps,GhostDrawerTriggerExposed,GhostDrawerOverlayElement,GhostDrawerOverlayProps,GhostDrawerOverlayExposed,GhostDrawerContentElement,GhostDrawerContentRole,GhostDrawerContentProps,GhostDrawerContentExposed,GhostDrawerTitleElement,GhostDrawerTitleProps,GhostDrawerTitleExposed,GhostDrawerDescriptionElement,GhostDrawerDescriptionProps,GhostDrawerDescriptionExposed,GhostDrawerCloseElement,GhostDrawerCloseProps,GhostDrawerCloseExposed,UseGhostDrawerOptions,UseGhostDrawerReturn,GhostDrawerContext, andResolveDrawerDirOptions(the options object ofresolveDrawerDir)
Themed exports from @ghostvue/themes: GhostDrawer, GhostDrawerTrigger, GhostDrawerOverlay, GhostDrawerContent, GhostDrawerTitle, GhostDrawerDescription, GhostDrawerClose (plus re-exported types and styles via ghost-drawer.css in default.css).
Props and configuration
export type GhostDrawerSide = 'start' | 'end' | 'top' | 'bottom'
export type GhostDrawerDirection = 'ltr' | 'rtl'
export type GhostDrawerContentRole = 'dialog' | 'alertdialog'GhostDrawer (root)
| Prop | Type | Default | Contract |
|---|---|---|---|
open | boolean | undefined | undefined | Controlled open state. Omit for uncontrolled mode. |
defaultOpen | boolean | false | Initial open state when open is omitted. |
modal | boolean | true | Enables focus trapping/looping, scroll lock, inert background siblings, aria-modal, and overlay. |
side | GhostDrawerSide | 'end' | Default viewport edge placement. |
dir | GhostDrawerDirection | undefined | undefined | Optional explicit writing direction for logical start / end edge mapping. |
GhostDrawerTrigger
| Prop | Type | Default | Contract |
|---|---|---|---|
as | GhostDrawerTriggerElement (Component | string) | 'button' | Element tag or component (for example GhostButton). |
disabled | boolean | false | Prevents opening/toggling when true. Uses native disabled on <button> / button components and aria-disabled="true" otherwise. |
GhostDrawerOverlay
| Prop | Type | Default | Contract |
|---|---|---|---|
as | GhostDrawerOverlayElement (Component | string) | 'div' | Element tag or component for the modal backdrop. |
portal | boolean | true | Renders overlay through GhostPortal when true, or inline when false. |
portalTo | GhostPortalTarget | 'body' | Teleport target passed to GhostPortal when portal is true. |
Renders only when both open and modal are true.
GhostDrawerContent
| Prop | Type | Default | Contract |
|---|---|---|---|
as | GhostDrawerContentElement (Component | string) | 'div' | Element tag or component for the drawer surface. |
side | GhostDrawerSide | undefined | undefined | Overrides the root side when provided; otherwise inherits the root side ('end'). |
dir | GhostDrawerDirection | undefined | undefined | Overrides the root dir when provided; otherwise resolves from root/ancestor/document. |
role | 'dialog' | 'alertdialog' | 'dialog' | Semantic role. 'alertdialog' turns off outside-click close by default. |
closeOnEscape | boolean | true | Whether Escape dismisses the topmost open layer. |
closeOnOutsideClick | boolean | undefined | true (false for 'alertdialog') | Whether pointerdown outside content (including the overlay) dismisses the drawer. |
portal | boolean | true | Teleports content through GhostPortal when true, or renders inline when false. |
portalTo | GhostPortalTarget | 'body' | Teleport target passed to GhostPortal when portal is true. |
GhostDrawerTitle, GhostDrawerDescription, GhostDrawerClose
| Component | Prop | Type | Default | Contract |
|---|---|---|---|---|
GhostDrawerTitle | as | GhostDrawerTitleElement | 'h2' | Element tag or component for the heading. |
GhostDrawerDescription | as | GhostDrawerDescriptionElement | 'p' | Element tag or component for the description. |
GhostDrawerClose | as | GhostDrawerCloseElement | 'button' | Element tag or component for the close button. |
GhostDrawerClose | disabled | boolean | false | Disables closing when true. |
v-model contracts
GhostDrawerownsopenviauseControllableState(v-model:open/open+update:open).- When
openisundefined, internal state starts fromdefaultOpenand changes on trigger, dismissable-layer, or close-control events while emittingupdate:open. - If a controlled parent ignores
update:open(false)on Escape, Close click, or outside pointerdown, the drawer remains open, keepsuseScrollLockanduseInertOthersactive, and does not restore focus to the trigger.
Events, callbacks, slots, and exposed methods
GhostDraweremitsupdate:openwith[open: boolean].GhostDrawerdefault slot receives{ open: boolean, close: () => void, side: GhostDrawerSide }, wheresideis the effective side (content override when set, otherwise the root side).GhostDrawerTrigger,GhostDrawerOverlay,GhostDrawerContent,GhostDrawerTitle,GhostDrawerDescription, andGhostDrawerCloseeach expose{ readonly element: HTMLElement | null, focus(options?: FocusOptions): void, blur(): void }.
State model
- Two binary open states:
'closed'and'open'. - Closed drawers release scroll lock,
inertattributes, dismissable-layer entries, and trapped focus scopes immediately on logical close.GhostDrawerOverlayandGhostDrawerContentrender withv-ifonuseGhostPresenceand stay mounted withdata-state="closed"(keepingdata-side/data-dir) only while their CSS exit slide runs (presence spec). data-state="open" | "closed"on the trigger, overlay, and content.
Loading, empty, disabled, read-only, and error states
GhostDrawerTrigger and GhostDrawerClose support disabled. Disabled guards run before consumer onClick / onKeydown handlers.
Async behavior
None. Open state changes synchronously; consumers own any async work inside the panel.
Consumer data
GhostDrawer holds no domain collections and never mutates consumer props.
Placement and RTL resolution
A portaled drawer (portal=true, portalTo="body") is a position: fixed child of document.body, so CSS inset-inline-start alone resolves against <html>'s direction rather than a localized <div dir="rtl"> subtree that wraps the trigger. GhostDrawerContent resolves its effective direction in priority order:
- Explicit
dirprop onGhostDrawerContent, then onGhostDrawer. - Closest
[dir="ltr" | "rtl"]ancestor of the content element (excluding<html>). - Closest
[dir="ltr" | "rtl"]ancestor of the trigger element (excluding<html>). document.documentElement.diron the client, otherwise'ltr'(including SSR when no explicitdiris given).
<html> is excluded from steps 2–3 so a portaled drawer can still see the trigger's localized subtree; dir="auto" and other values are skipped. The resolution runs after mount (and again after an initial portal move), so the server and first client render agree on explicitDir ?? 'ltr'.
GhostDrawerContent binds data-side, data-dir="ltr" | "rtl", and sets the dir attribute on the host when the resolved direction is rtl (or when a direction was passed explicitly) so interior content flow matches the edge.
side | data-dir="ltr" edge | data-dir="rtl" edge | Entry slide vector (@starting-style) |
|---|---|---|---|
'start' | Left (left: 0) | Right (right: 0) | -100% 0 in LTR; 100% 0 in RTL |
'end' | Right (right: 0) | Left (left: 0) | 100% 0 in LTR; -100% 0 in RTL |
'top' | Top (top: 0) | Top (top: 0) | 0 -100% |
'bottom' | Bottom (bottom: 0) | Bottom (bottom: 0) | 0 100% |
Accessibility contract
Follows the WAI-ARIA APG Dialog (Modal) and Alert Dialog patterns.
Semantics and relationships
GhostDrawerTrigger:type="button"(whenas="button"),aria-haspopup="dialog",aria-expanded,aria-controls="<contentId>",data-part="trigger",data-state,data-side.GhostDrawerOverlay:aria-hidden="true",data-part="overlay",data-state="open",data-side.GhostDrawerContent:role="dialog" | "alertdialog",aria-modal="true"whenmodal=true(omitted otherwise),tabindex="-1",data-part="content",data-state="open",data-side,data-dir,aria-labelledbywhenGhostDrawerTitleis mounted (unlessaria-label/aria-labelledbyis passed), andaria-describedbywhenGhostDrawerDescriptionis mounted (unlessaria-describedbyis passed).- Development diagnostics
GHOST002(missing accessible name) andGHOST003(role="alertdialog"without a description) are shared withGhostDialog.
Keyboard interaction
| Key | Where | Behavior |
|---|---|---|
Enter / Space | GhostDrawerTrigger | Opens/toggles the drawer (role="button" + tabindex="0" for non-button as). |
Escape | Topmost open layer | Closes the drawer when closeOnEscape is true and restores focus to trigger. |
Enter / Space | GhostDrawerClose | Closes the drawer and restores focus to the trigger. |
Tab / Shift+Tab | Inside GhostDrawerContent | Loops within the drawer when modal=true; moves freely when modal=false. |
The drawer is not a composite widget, so there is no roving tabindex; every tabbable descendant is a normal Tab stop. Arrow keys are not handled, so writing direction does not change keyboard behavior, only placement.
Focus behavior
- Modal:
useFocusScope({ trapped: true, loop: true, autoFocus: true, restoreFocus: true }),useScrollLock(true), anduseInertOthers([content, overlay], true)(skipping[data-ghost-live]). A modal drawer open at mount still moves focus inside. - Non-modal: no overlay or
aria-modal;trapped: false, loop: false,autoFocus: () => !openedAtMount; dismissing via an outside pointerdown on a focusable control keeps focus on that control. - Nested overlays: per ADR 0012 and
dismissable-layer-stack.ts, an upper portaledGhostPopover/GhostSelect/GhostCombobox/GhostDropdownMenuor a nestedGhostDialog/GhostDraweropened insideGhostDrawerContentownsEscapeandTabwhile active; inline (portal=false) popovers stay bounded inside the modal drawer's focus trap.GhostDraweruses its own injection key, so a nestedGhostDialog's parts never register on the drawer (and vice versa).
Assistive technology expectations
Screen readers announce the drawer as a dialog with its title and description, exactly like GhostDialog; side and direction are visual-only.
Rendering and customization
- Headless classes:
.ghost-drawer-overlayand.ghost-drawer-content.data-parthooks:trigger,overlay,content,title,description,close. Placement hooks:data-side,data-dir. - Themed CSS (
packages/themes/src/ghost-drawer.css) under@layer ghostvue-theme:- Uses
--ghost-scrim,--ghost-elevation-4-*,--ghost-radius-lg,--ghost-border-hairline-width,--ghost-surface-fg,--ghost-space-inset-lg,--ghost-space-gap-md,--ghost-focus-ring-*, andoverscroll-behavior: contain, with no hardcoded colors or non-zeropx/ms/s/rem/emliterals. - Side panels (
start/end):block-size: 100dvh,inline-size: min(calc(100dvw - 2 * var(--ghost-space-inset-lg)), 42ch), inner-edge--ghost-radius-lgcorners, outer-edge border0. - Sheet panels (
top/bottom):inline-size: 100dvw,max-block-size: min(calc(100dvh - 2 * var(--ghost-space-inset-lg)), 85dvh), inner-edge radius, outer-edge border0. - Entry:
@starting-styleslide + fade (opacityandtranslatewith--ghost-motion-enter-*) underprefers-reduced-motion: no-preference. prefers-reduced-motion: reduce:translate: nonein resting and starting states, opacity-only fade with--ghost-motion-fade-duration/--ghost-motion-easing-standard.forced-colors: active:Canvas/CanvasTextsurface, no shadows,Highlightfocus outline.- Title/description rules use child combinators so a nested dialog's parts are not restyled.
- Uses
Environment behavior
SSR and hydration
- Deterministic IDs via
useGhostId('ghost-drawer-*'). - Closed drawers render only the trigger.
defaultOpen: truerenders cleanly with nowindow/documentreads during setup;focusPortalReadydefers initial focus scope activation by one tick when portaling on mount so Teleport does not drop focus.- Without an explicit
dir, server HTML always hasdata-dir="ltr"; RTL subtrees refine it after mount. Passdirexplicitly for RTL pages that render a drawer open on the server.
Mobile and touch
useDismissableLayer uses capture-phase pointerdown for mouse, touch, and pen parity. Dynamic viewport units (dvh / dvw) keep panels inside the visible viewport when mobile browser chrome collapses. No gestures (non-goal).
Performance
Zero global listeners, scroll locks, or inert attributes exist while closed. Direction resolution walks DOM ancestors only on open/mount changes.
Composition
- Internal
packages/vue/src/dialog-shared.ts(shared withGhostDialog*): controllable state + IDs, part registration, trigger/close activation, overlay, and content mechanics. GhostPortal,useDismissableLayer+dismissable-layer-stack.ts,useFocusScope,useScrollLock,useInertOthers,useControllableState,useGhostId.- Distinct injection keys (
ghostDialogContextKey/ghostDrawerContextKey). No focus, dismissal, scroll-lock, or isolation code is duplicated.
Test plan
- Unit / behavior (
packages/vue/src/GhostDrawer.test.ts):resolveDrawerDirpriority (explicit, content ancestor, trigger ancestor,<html>, SSR fallback,dir="auto"),useGhostDrawer, ARIA linking, side override propagation, portaled RTL subtree, explicitdir, modal trap / scroll lock / inert / focus restore, overlay and Close dismissal, controlled parent ignoringupdate:open(false), non-modal behavior,closeOnEscape/closeOnOutsideClick/alertdialog, nestedGhostDialog,GHOST002/GHOST003, exposed refs,as/disabled, and errors outside the root. - Dialog regression:
packages/vue/src/GhostDialog.test.tsandtests/integration/ghost-dialog-themed.test.tspass unchanged. - SSR:
packages/vue/src/overlay-ssr.test.ts(Node, no globals) andtests/integration/ssr-hydration.test.ts(closed and open with explicitdir). - Themes:
tests/integration/ghost-drawer-themed.test.tsandtests/integration/ghost-drawer-theme-css.test.ts(tokens, physical edge mapping,@starting-style, reduced motion, forced colors, no literals). - Browser (
tests/e2e/drawer.spec.ts): Tab / Shift+Tab wrap withtoBeFocused(), Escape, overlay click, Close, Enter/Space on the trigger, physical edge geometry for every side in LTR and inside an RTL subtree, reduced-motiontranslate: none, non-modal page interaction, nested dialog Escape order, and Axe with the drawer open and closed. - Cross-browser (
@cross-browser): the RTL-subtree edge flip and nested dialog Escape order also run in Firefox and WebKit. The drawer shares the dialog's modal outside-press handling, including the WebKit focus reapply described under Focus behavior indocs/components/dialog-spec.md.
Documentation plan
docs/components/drawer.md with <GhostExample /> entries for drawer/basic, drawer/themed, drawer/sides, drawer/non-modal, and drawer/nested; generated reference pages from manifests; roadmap row 41; playground fixtures.
Compatibility and release impact
- Additive
minorChangeset for@ghostvue/vueand@ghostvue/themes. GhostDialog*parts now delegate todialog-shared.ts; their public API, markup, and tests are unchanged.GHOST002/GHOST003messages now name both dialog families.
Open architectural questions
None.