Modal
HkModal is the library's window frame: a centered dialog over a dimmed, blurred backdrop, with a title bar, a scrolling body, an optional footer band, and the whole window-layer stack behind it — focus trap, Escape and overlay dismissal, a history entry the back gesture consumes, z-banding against other surfaces, and a content-driven height morph. Every dialog in the library that is not a toast is built on this frame.
- Reach for it whenever a task must finish before the page makes sense again: a form, a settings pane, a destructive choice. Anything that can be read while the page stays usable belongs in a popover, not here.
- On phones the same frame docks as a bottom sheet (below 768px), so one component covers both form factors; Drawer is the deliberate side panel, and AdaptiveDialog is the wrapper that picks between this frame and a drawer by viewport width.
- The Rust Modal is the two-layer contract — mask plus frame — rendered in place rather than teleported, and without the stack, focus or motion machinery. The third section lists exactly what it leaves to the host.
Import
;
use *; // Modal, ModalAction, ModalActionVariant
use *; // ModalProps, rsx!, VNode, Element, EventHandler, KeyboardEvent, MouseEvent
use HkPad; // the named padding step the `padding` prop takes
The Rust form is a plain function, Modal(ModalProps { … }). Inside rsx! every prop may be omitted, and the closed default renders nothing at all. HkPad is the one prop type that lives outside the crate glob — it sits in hikari_components::utils, not the prelude, so a host that sets padding: Some(HkPad::Lg) needs that third import line.
Controlled open, and what dismissal means
modelValue is the only state. The component never closes itself: the ✕ (hidden when closable is false), a press on the overlay and the Escape key all emit update:modelValue with false, and the dialog stays on screen until the caller writes the prop back. Whichever surface asked, the one channel is update:modelValue — there is no separate close event.
A press inside the frame never reaches the overlay (the frame stops propagation), so clicking a form field is not a dismissal. Escape is read at the root, and a nested control that already consumed the key (event.defaultPrevented) keeps it: a picker inside the dialog can own Escape without the window closing underneath it.
surfaceTitle is the accessible name of the dialog (aria-label) and wins over title; a header-less window — a lightbox, a chart — passes it so the surface still has a name. title also fills the visible h2. [D] The two names are not identical in effect: in Vue surfaceTitle also labels the popup-manager layer that the modal-stack breadcrumb lists; the Rust form has no stack, so there it only reaches aria-label.
Both cards show the open frame statically — a snapshot never runs the dismissal paths, so the ✕ only paints there. In the TSX card nothing answers the press while the snapshot is rendered; wire onUpdate:modelValue to a ref (see the interaction example below) and the ✕, the mask and Escape all close it.
Widths, padding and the footer band
width accepts a named preset — xs 20rem, sm 32rem (the default), md 40rem, lg 56rem, xl 72rem — or any CSS max-width value ("560px", "50%"). Both forms resolve the preset first and then cap the result at min(<value>, calc(100% - 2 * var(--viewport-gutter, 16px))), so the frame never runs edge to edge; the ≤767px sheet rule overrides the cap to full width, which is the intentional phone layout. A value that is neither a preset nor a length (a stray "wide") is passed through verbatim — the browser drops it and the frame spans the viewport; Vue warns about that once in development builds, the Rust form stays silent.
padding retunes the body only: it writes the shared --hk-pad token (none / xs / sm / md / lg), which outranks the sheet's 1.5rem body padding. On the Rust side the prop is Some(HkPad::Sm) and the type is imported separately (see above); the example below leaves it out so the fence stays inside the prelude. The title bar and the footer keep their own theme tokens, so a host cannot accidentally collapse the header by tightening the body.
The footer is one of four things, in precedence order: the footer slot renders verbatim; otherwise footerActions renders as small buttons in the order given; a footerLead slot sits at the inline start of that same row, with the actions pinned at the inline end; with none of them there is no footer band at all (not an empty bordered strip). A footer action's variant defaults to secondary and accepts primary / danger / ghost / outline, plus its own loading and disabled.
The runtime the frame carries, and the Rust subset
Beyond markup, the Vue frame runs the window-layer machinery: a popup-manager z-band (overlay below, frame above, both renumbered as surfaces stack), a focus trap on Tab with the first focusable element focused on open and focus restored to the opener on close, a backGuard history entry so the browser's back gesture closes the window instead of leaving the page, a content hold over the leave transition, a size morph that grows and shrinks the frame with the content instead of snapping, and afterLeave once the leave animation finished. backGuard defaults to true and is only meaningful together with closable: a window that refuses Escape also refuses to swallow the back gesture.
Two content options are Vue-only. draggable turns the header into a grab handle that moves the desktop frame (the phone sheet never drags); windowed + overscanScreens render only the children near the viewport inside the scrolling body, and autoFollow keeps a streaming body pinned to the bottom — showing a localized "Auto" tag while it follows and a back-to-bottom FAB once the user scrolls away.
[D] The Rust Modal mirrors the frame contract (same .hk-modal-* classes, same sheet compiled from HkModal.scss) and has none of that runtime. It renders in place with position: fixed and no <Teleport>, so a host must keep it out of transformed or contained ancestors; it carries no z-band, so DOM order and the host's stacking context decide what paints on top. Escape is bound on .hk-modal-root exactly as in Vue — but without a focus trap the dialog only receives the key while something inside it holds focus, so a Rust host either focuses the frame (tabindex="-1") or wires Escape itself. There is no afterLeave (no leave driver), no back guard, no drag, no windowing and no auto-follow.
footerActions on the Rust side are data with an optional on_click: the handler is wired into the mirrored Button, but the snapshot does not execute it. on_close is shared by the ✕, the overlay press and Escape.
The press sets the signal to false; the reopened frame renders the empty vnode until a host writes true back, which is the same caller-owned contract as the Vue prop. In a static snapshot nothing runs, so the card paints the open frame around its "Reopen" button.
Interaction
The interactive example keeps modelValue in a ref: the ✕, the mask and Escape all emit false, the host writes it back, and the frame unmounts after its leave. The Rust side of this card is the declarative shape above; a snapshot has no handler to run.
API
Vue
Props
| Name | Type | Default | Required |
|---|---|---|---|
| modelValue | Boolean | — | ✓ |
| title | String | undefined | — |
| closable | Boolean | true | — |
| padding | String as PropType<HkPad> | undefined | — |
| width | String as PropType<ModalWidth> | "32rem" | — |
| contentClass | String | undefined | — |
| surfaceTitle | String | undefined | — |
| closeLabel | String | undefined | — |
| footerActions | Array as PropType<ModalAction[]> | undefined | — |
| windowed | Boolean | false | — |
| overscanScreens | Number | 1 | — |
| autoFollow | Boolean | false | — |
| backGuard | Boolean | true | — |
| draggable | Boolean | false | — |
Emits
| Event | Payload |
|---|---|
| update:modelValue | boolean |
| afterLeave | — |
Rust
Props — Modal
| Prop | Type | Default | Description |
|---|---|---|---|
| open | bool | false | Controlled open state (Vue: modelValue). |
| title | Option<String> | None | Header title (hk-modal-title). |
| closable | bool | true | Render the ✕ and allow overlay-click close (Vue default true). |
| padding | Option<HkPad> | None | Body container-padding override (--hk-pad); unset keeps the sheet's own body padding. |
| width | String | "32rem".to_string() | Named preset (xs…xl) or any CSS max-width value (default "32rem"). |
| content_class | String | "" | Extra class appended to the .hk-modal-content frame so hosts can restyle the surface without forking the modal. |
| surface_title | Option<String> | None | Accessible name for header-less surfaces; takes precedence over title for aria-label. |
| footer_actions | Option<Vec<ModalAction>> | None | Footer buttons rendered when no footer slot is provided. |
| children | Element | (empty) | Body content (Vue: the default slot). |
| header | Option<Element> | None | Header slot body rendered inside hk-modal-subheader. |
| header_lead | Option<Element> | None | Header lead slot (inline-start of the title bar). |
| header_actions | Option<Element> | None | Header actions slot (inline-end, before the close button). |
| footer | Option<Element> | None | Custom footer content (wins over footer_actions). |
| footer_lead | Option<Element> | None | Footer lead slot (inline-start of the footer row). |
| on_close | Option<EventHandler<MouseEvent>> | None | Fired when the user asks to close (✕ / overlay click / Esc). |
| close_label | Option<String> | None | Accessible name of the header's ✕ button (Vue closeLabel). |
| backdrop | Option<Element> | None | Window-level material layer (Vue: the backdrop slot). |
| draggable | bool | false | Make the header a grab handle that moves the frame (Vue draggable, default false). |
| instance_key | String | "" | The per-instance identity the drag latch is keyed by (the scene/node_canvas.rs pattern). |
| shift_x | Option<f64> | None | Horizontal drag shift in px (Vue: dragShift.value.x), rendered as --hk-modal-shift-x. |
| shift_y | Option<f64> | None | Vertical drag shift in px (Vue: dragShift.value.y), rendered as --hk-modal-shift-y. |
| on_drag_shift | Option<EventHandler<(f64, f64)>> | None | Fired while a drag publishes a new shift: (x, y) in px, already resolved against the shift the press started from (Vue: dragShift.value = { x, y }). |
| windowed | bool | false | [carrier] Virtualize the scrolling body (Vue windowed). |
| overscan_screens | i32 | 1 | [carrier] How many viewports of overscan the windowing above reads (Vue overscanScreens, default 1). |
| auto_follow | bool | false | [carrier] Keep a streaming body pinned to the bottom (Vue autoFollow). |
| back_guard | bool | true | [carrier] Consume the system back gesture while open (Vue backGuard, default true; only meaningful together with closable). |
Accessibility
- The frame is role="dialog" with aria-modal="true" and takes its aria-label from surfaceTitle first and title second. A dialog with neither has no accessible name — pass one of the two, even for chrome-only windows.
- Vue traps Tab inside the frame, moves focus into it on open and returns focus to whatever was focused before on close; that restore happens on the finalize edge, i.e. after the leave animation. The Rust frame ships the role / aria-modal / aria-label attributes and tabindex="-1" but no trap and no focus management: the host has to place focus and restore it.
- Escape closes only while closable. Vue reads the key at the root, swallows it when it handles it (so page-level Escape listeners see no second action) and yields to a nested control that already called preventDefault; the Rust frame mirrors the press handling on the root, but without a trap it only sees Escape while the focus is inside the dialog.
- The ✕ is a real button named by the i18n key hikari::modal.close ("Close"); Vue additionally accepts a closeLabel for a more specific wording ("Dismiss message"). The Rust form always uses the localized default.
- The overlay is a plain div, not a focusable element: it is a pointer dismissal only, and the keyboard path to the same outcome is Escape. Overlay presses are gated on closable, so a non-closable window cannot be dismissed by a stray tap.
- While open, Vue pushes a history entry (backGuard) so the system back gesture closes the topmost window; it is released on close and skipped for non-closable windows, which must not swallow a gesture they cannot honour.
Related components
- AdaptiveDialog — the same contract, but it renders a drawer instead of this frame on phones.
- ConfirmDialog — a 24rem confirmation built on this frame, with the dismiss path wired to cancel.
- Drawer — the edge-docked window, when the surface should come from a side rather than the centre.
- ProgressDialog — a non-closable progress window driven by a singleton service.
- MessageBox — the imperative confirmation API for call sites that do not render a component.
- Popover — the anchored layer for surfaces the page stays usable behind.