AdaptiveDialog

AdaptiveDialog

HkAdaptiveDialog is one dialog contract with two shells: above 768px it renders HkModal — the centered frame — and below that it renders HkDrawer docked to the bottom edge, the phone sheet. The caller passes one modelValue, one title, one footer and one body, and the surface adapts on its own; overlay, z-band, body scroll lock, focus handling and Escape all come from whichever inner component is mounted, never re-implemented in the wrapper.

  • Reach for it when the same form or summary must be usable on a laptop and on a phone, and the phone answer really is a sheet rather than a full page.
  • The wrapper is a shell picker plus four seams, not a third dialog: the modal width preset chain, the drag handle, the auto-follow body and the window stack are all still the inner components' business.
  • If the design calls for a side panel, use Drawer directly; if the surface is always the centred frame, use HkModal — the extra breakpoint is only worth paying for when the phone layout differs.

Import

tsx
1
import { HkAdaptiveDialog, type ModalAction } from "@celestia-island/hikari";
rust
1
2
3
use hikari_components::*;          // AdaptiveDialog, adaptive_dialog_mode, adaptive_dialog_shell_class,
                                   // AdaptiveDialogMode, ADAPTIVE_DIALOG_BREAKPOINT
use hikari_components::prelude::*; // AdaptiveDialogProps, ModalAction, ModalActionVariant, rsx!, VNode

The Rust form is a plain function, AdaptiveDialog(AdaptiveDialogProps { … }). Inside rsx! every prop may be omitted and a closed dialog renders nothing. The one prop Vue does not have is viewport_width — the mirror's stand-in for Vue's live breakpoint read (see the third section).

One contract, two shells

The split is useBreakpoint().isMobile, which is width < 768: exactly 768px is already the desktop modal. The four things the wrapper normalizes are:

  • the body — the default slot feeds the modal's body or the drawer's body;
  • the header — on the modal it is the sub-header band under the title bar; on the drawer the shell composes title + slot itself, because HkDrawer's header slot replaces its title span;
  • the footer — the footer slot wins over footerActions in both shells, the same precedence HkModal applies on its own; HkDrawer has no footerActions prop, so the wrapper renders the equivalent small button row inside the drawer's footer band;
  • the dismissal — update:modelValue and afterLeave are forwarded from whichever shell is mounted.

mobileSize is the drawer's docked-axis length, 70vh by default — which is also HkDrawer's cap for a bottom panel, so a taller sheet needs a panelClass with its own max-height. panelClass applies to the mobile panel only; the desktop modal has no equivalent hook (attrs do not reach a teleported panel either).

This example is rendered in the browser and needs JavaScript.

The TSX preview shows the shell that matches the reading viewport, chosen live. The Rust fence passes no viewport_width, so it takes the prop's default 1280.0 and the card above paints the modal shell — div.hk-modal-root, with the footer action row the inner Modal renders — whatever the terminal's window actually is. That is the whole point of the section below; the next example asks for the sheet explicitly.

footerActions render in both shells. On Vue they are HButtons inside whichever footer band is mounted. On Rust they are the crate's own Buttons, and a press is inert (see "Smaller differences" below).

The breakpoint is a prop on the Rust side

[D] Vue reads the viewport live: the component subscribes to useBreakpoint() and re-renders into the other shell the moment the window crosses 768px. The Rust form takes viewport_width: f64 instead and resolves it through the pure adaptive_dialog_mode — >= 768.0 is the modal, everything below (negative and NaN included) is the sheet. There is no resize listener: a window that crosses the breakpoint while the dialog is open does not re-shell it — the host measures, re-renders with the new width, and the next paint picks the other shell. The default is 1280.0, deliberately a desktop width, so a host that forgets the prop gets the frame rather than a surprise sheet.

adaptive_dialog_shell_class(mode) returns the band each branch paints (hk-modal-content / hk-drawer-panel) and AdaptiveDialogMode::token() the "modal" / "sheet" spelling — both are pure helpers a host can use to branch its own copy without re-deriving the rule.

[D] On the sheet branch the Rust row maps all five Vue action variants straight onto ButtonVariant, outline included. The inner Modal mirror folds outline into secondary in its own footer row; the wrapper does not, so the same ModalAction can come out looking different depending on which shell drew it.

This example is rendered in the browser and needs JavaScript.

The Rust card prints the two resolutions beside a dialog opened with a phone width, so it paints the sheet — div.hk-drawer-panel.hk-drawer-bottom — while the TSX card paints whatever shell its viewport resolves to.

Smaller differences worth knowing

closable, footerActions and the body pass through untouched. What does not pass through is worth listing, because a wrapper that silently drops a prop is the classic dialog bug:

  • draggable reaches the desktop modal and is ignored on the phone (HkDrawer has no drag); the Rust form does not mirror it at all — the Modal mirror has no drag handle.
  • Vue's width is a modal concern only: the drawer always takes mobileSize on its docked axis with max-width: 85vw for a side panel and max-height: 70vh for a bottom one.
  • afterLeave has a Vue caveat the wrapper documents itself: if the viewport crosses the breakpoint while a leave transition is in flight, the inner transition unmounts without firing its after-leave hook, so that one close forwards neither afterLeave nor the modal's focus restore. Resource-wise it is clean (the popup handle and the scroll lock are released on unmount), but a caller that hands focus on afterLeave must not depend on it during a live shell flip. The Rust form has no afterLeave at all — neither shell mirror has a leave edge.
  • footerActions arrive as data on the Rust side (label / variant / loading / disabled); a press is inert. A Rust dialog whose footer must act passes the footer slot, which wins over footer_actions in both shells exactly as in Vue.
This example is rendered in the browser and needs JavaScript.

API

Vue

Props

NameTypeDefaultRequired
modelValueBoolean—✓
titleStringundefined—
closableBooleantrue—
widthString as PropType<ModalWidth>"32rem"—
draggableBooleanfalse—
mobileSizeString"70vh"—
footerActionsArray as PropType<ModalAction[]>undefined—
panelClassStringundefined—

Emits

EventPayload
update:modelValueboolean
afterLeave—

Rust

Props — AdaptiveDialog

PropTypeDefaultDescription
openboolfalseControlled open state (Vue: modelValue); closed renders nothing.
titleOption<String>NoneDialog title (both shells' title bar + the accessible name).
closablebooltrueRender the ✕ and allow overlay/Escape dismissal (Vue default true).
widthString"32rem".to_string()Desktop modal width — a preset or any CSS max-width (Vue: width).
mobile_sizeString"70vh".to_string()Mobile drawer height (Vue: mobileSize; HkDrawer clamps at 70vh).
panel_classString""Extra classes for the mobile drawer panel (Vue: panelClass; the desktop modal has no equivalent hook, like Vue).
viewport_widthf641280.0HOST-MEASURED viewport width in px — the mirror's stand-in for Vue's live useBreakpoint().
footer_actionsOption<Vec<ModalAction>>NoneFooter buttons rendered when no footer slot is given (Vue: footerActions; see the header delta — the verbs are inert).
childrenElement(empty)Body content (Vue: the default slot).
headerOption<Element>NoneHeader slot (Vue: the header slot — the modal's sub-header, or the content stacked under the drawer title).
footerOption<Element>NoneFooter slot (Vue: the footer slot; wins over footer_actions).
on_closeOption<EventHandler<MouseEvent>>NoneFired when the user asks to close (✕ / overlay click / Esc).

Accessibility

  • The accessible contract is the mounted shell's. The desktop branch is the modal's role="dialog" + aria-modal="true" + aria-label from the title; the mobile branch is the drawer's panel, role="dialog" with aria-modal following overlay and aria-label from the title. Because the wrapper never sets an overlay prop, the drawer is always created with overlay: true, so a phone dialog is always announced as modal. A dialog with no title has an unnamed surface in both shells — pass one.
  • Escape, the ✕, the mask and Tab cycling are whatever the inner component does: the modal traps Tab and restores focus on close, the drawer traps Tab inside its panel. The wrapper adds no key handling of its own.
  • [D] The wrapper does not pass a panelClass-independent body padding, a padding hook or surfaceTitle to either shell: the only naming channel is title, and the modal's aria-label/stack labelling therefore always equals the visible heading.
  • A shell flip mid-interaction moves the whole subtree; because the wrapper forwards focus work to the shells, the leave-only caveat above is the one place where focus can be skipped. Do not build an accessibility flow (a focus hand-off to a field, an announcement) on afterLeave while the viewport may change under it.
  • On the Rust side neither shell ships a focus trap, so a host must place and restore focus itself — the wrapper inherits exactly that gap.

Related components

  • Modal — the desktop shell, and the component to use when the surface does not need to adapt.
  • Drawer — the mobile shell, and the component to use when the panel should dock to a side on purpose.
  • ConfirmDialog — a short confirmation that stays the compact frame at every width.
  • ProgressDialog — a non-closable progress window over the same frame.
  • Popover — the anchored layer that already switches to a phone sheet on its own.