Skip to content

BbDialog

The centred modal: a native dialog over the page, a bottom sheet on phones.

import { BbDialog } from 'bitboss-ui';

On this page

Use it for

Reach for BbDialog when someone has to finish one focused task without losing the page behind it. An edit form, a create step, a decision that has to be made now. Nothing else on the page is reachable while it is open.

Use something else when

  • BbOffCanvas: the panel sits beside the task instead of replacing it
  • BbPopover: the panel is anchored to the control that opened it
  • BbDropdown: the anchored content is a menu of actions
  • BbConfirm: it is a plain yes/no, above all a destructive one
  • BbGallery: it is a full-screen viewer for photos

Also see: Validated forms.

BbDialog is the library's modal: give it an id and a title, and put v-bb-dialog on the button that opens it.

Passthrough

Hover or tap a part to outline it. The toggles turn on loading, errors and warnings where the component has them; only parts get a row.

Open by id

Most dialogs need only a button that opens them, so they need no ref(false), no @click and no v-model. The value of the directive is the dialog's id, in inner quotes:

vue
<BbButton v-bb-dialog="'invite'">Invite teammate</BbButton>

<BbDialog id="invite" cancel ok="Send invite" title="Invite teammate">
    …
</BbDialog>

When the dialog needs to know what it was opened for, pass that as data: v-bb-dialog="{ id: 'edit-member', data: member }". Every row opens the same dialog with its own data. Write one <BbDialog id> per id, never one per row: the id is also the element's DOM id, and two elements with one id are broken HTML. The dialog reads data in two places:

  • the default, header and footer slots receive it as data, typed any, so data.fullName reads with no cast;
  • useBbDialog<T>(id) returns it typed, along with open, isReady, show(data?), hide(), complete(value) and reset(). A component inside the dialog can call it too, or call useBbDialog() with no argument: the dialog around it, whatever its id.

data is the opening's own copy of what you passed (see the edit form below), and it stays set until the close transition has run, so the content never flashes empty as the dialog fades out.

  • Three closes. ok and complete(value) close with a result for whoever opened the dialog. The handle's hide() is the code's close, with no result. Both close even under prevent-close. cancel and the slots' close() are the user's close, like the ×.
  • A show() on an open dialog changes nothing. It joins the opening already showing (its promise, its data); the new data, trigger and onComplete are ignored. A show during the close transition opens it again.
  • Lookup starts at the trigger. The directive looks for the dialog in the component whose template it sits in and in what that component renders, then in its parents. A dialog wrapped in a component of its own, such as <EditMemberDialog />, opens from the page that renders it, and two pages can each have an id="edit".
  • v-model still works, and wins over the directive. Keep it for a dialog your state opens, from a route or a watcher, rather than from a button.
  • The button gets aria-haspopup="dialog", aria-expanded and aria-controls, and focus returns to it on close. On a phone the adaptive sheet opens the same way.

npx bitboss-ui check and the ESLint rule bitboss-ui/portal-names report an id that no <BbDialog id> in the project declares (unknown-dialog).

Write the footer as props: cancel and ok render library buttons, in that order, and nothing renders unless you write it.

No statements downloaded yet.

  • Each takes three forms: true (a bare attribute, the locale's Cancel or OK), a label, or a button config with text, variant, size, prepend:icon, append:icon, iconOnly, block and onClick.
  • ok completes with data, after its onClick if it has one. With a BbForm inside it submits the form instead (Editing a record). false from onClick keeps the dialog open.
  • cancel is a dismissal (reason: 'close'), refused while a save runs.
  • @complete gets the same value as the opener's onComplete, before it. Return a promise and ok spins while the dialog stays locked; false or a throw keeps it open.
  • actions replaces both with an array of button configs, each running its onClick, then completing.
  • href (or to) in a config makes a link. A plain click navigates in this tab, so the dialog completes and closes; a new tab leaves it open.

While one button works, the others ignore clicks. ok is never disabled until the form is valid: the user submits, and the form shows what is missing. A footer that needs anything else, a Clear button or a primary that waits for a selection, is the footer slot.

Give a button config items and it becomes a split button: the button is its main part, and the entries open in a menu beside it. Each entry's onClick runs as the button's own would, under the same lock, and then the dialog completes. An entry on ok never submits the form.

Draft, not published.

The plugin sets the look of every dialog's buttons. A dialog's own config wins, and the plugin never adds a button:

ts
// nuxt.config.ts
export default defineNuxtConfig({
    bitboss: {
        components: {
            BbDialog: {
                okProps: { variant: 'primary' },
                cancelProps: { variant: 'ghost' },
            },
        },
    },
});

BbOffCanvas and BbConfirm take the same two keys.

A dialog in the URL

With navigation, opening the dialog writes ?dialog=true to the URL (or the key you name with query-key), and closing it takes the key away.

  • Back closes it, like Escape: the result's reason is 'escape', and a dialog that refuses Escape refuses Back too. A menu, popover or tooltip open over the dialog closes first, where the browser has close watchers.
  • A close the browser forces counts as Escape. Some browsers close the dialog on a second Back without asking the page: v-model, the scroll lock and the result follow as they would on the key.
  • A link with the key opens it on load, so a support email can point at it.
  • replace swaps the history entry instead of adding one: Back then leaves the page.
  • Two URL dialogs on one page each need their own query-key. A BbOffCanvas writes offcanvas by default, so a dialog and a panel never collide.

Editing a record

Each row's Edit button hands the dialog its record as data, and the dialog gets its own copy of it, made fresh on every opening. So the form binds data directly, with no draft to seed and nothing to clear. ok submits the form, and what the save resolves is what the row gets back; any other close throws the copy away.

Edit Marta, cancel, then edit her again: the cancelled change is gone.

  • Marta VilloresiHead of Product
  • Lukas BrandtNo job title

Always pass title. It draws the header and gives the dialog its accessible name; without one a screen reader announces "dialog" and nothing else.

  • The row stays untouched until Save. Plain objects and arrays are copied all the way down; anything else (a Date, a File, a class instance) is the object you passed.
  • Compare by id, never by identity. data is not the row you passed, so onComplete (or the code after await show()) is where the page writes the result back, as replace does above.
  • One form, nothing to wire. ok is the form's submit button, so Enter in a field saves too. With no form, or two, ok completes with data. Never call complete() in a form dialog.
  • A refused save stays open. Let the save reject: a validation answer (a BbValidationError, or a Laravel-style 422) puts each message under its field (Server errors).
  • While the save runs, the form is read-only and the dialog refuses every close until it settles (Controlling dismissal).

Create and edit in one dialog

A create has no row to pass, so data would be undefined. Give the dialog a default-data object: every opening without data gets a fresh copy of it, and an edit lays its row over it.

  • Send the Q3 invoices · urgent
  • Renew the domain
  • The fields bind data.title with no guard, on a create and an edit alike.
  • reset() (in the slots, or useBbDialog(id).reset()) restores the keys default-data declares from a fresh copy and keeps every other key: Clear empties a task, and on an edit the row's id stays, so the cleared task still saves as an edit. It never goes back to the row's values; Cancel is what discards an edit.
  • Every close resets it as well, so nothing needs doing on @show.

The body is lazy: it renders when the dialog opens and unmounts after the close transition, so every opening starts fresh, the state of what is inside it included. A reopen during the close transition gets a fresh body too. eager keeps it mounted from the start and across closes, with data back to undefined while it is closed; use it only when a test or measurement must read the body before the first open. @hidden fires after the close transition, the place to tear down expensive content.

What the opener gets back

Every opening ends one way or the other. onComplete on the directive hears only a completion: ok, or complete(value). For the rest, open from code: show() returns a promise of { completed: true, value } or { completed: false, reason }.

Pick a format, or close the dialog any other way.

Pick a format, then try Escape, the backdrop, the × and Cancel: each names its reason ('escape', 'backdrop', 'close'). hide() and a v-model set to false say 'hide'.

@hide carries the same result as the close starts, so the dialog's own listener knows a save from a dismissal. A live preview reverts on a dismissal with no flag of its own:

  • It settles when the close starts, so the page can update while the dialog fades out. It never rejects and never hangs.
  • Close a save with ok or complete(), not by writing the model, to tell it from a cancel. On a v-model dialog too, it closes through the model and reports { completed: true }.
  • A click that awaits the dialog spins like any async click: put disable-auto-loading on that button. onComplete never spins.
  • Prefer the directive on a button. show() is for opens no button makes, or a flow that needs the reason; the directive keeps the button's aria-haspopup, aria-expanded and aria-controls.
  • useBbDialog<In, Out> types both ends; untyped, they are any.

The page saves

When the page owns the save (it knows the endpoint and the list to update), onComplete returns the request's promise. Completing waits for it, and the dialog stays open and locked until it settles: the ×, Cancel, Escape and the backdrop are refused, and the button that completed spins.

Rename Harbor to Atlas: the server refuses, and the dialog stays open with the message under the field.

  • Harbor
  • Atlas
  • Resolved, the dialog closes and the opening settles { completed: true, value }. Resolved false, it stays open and nothing is reported.
  • Rejected with a validation answer (a BbValidationError, or a Laravel-style 422), the dialog stays open with the user's edit and each message shows under its field, as in the demo. Any other error keeps it open too and is reported once, to app.config.errorHandler.
  • From code it is edit.show(row, { onComplete: save }), on an id handle and a component handle alike. A synchronous onComplete, or none, closes at once.
  • onComplete is just a function. A trigger inside a child component gets the page's save the way your app already shares things: a function prop (:save="saveMember"), a page provide / inject, or a store action. Not an emit: an emit cannot return the promise.

A bare Inertia visit returns no promise. usePromiseRouter from the Inertia helpers makes one: it rejects with a BbValidationError (the messages under .errors) on a 422, and a cancelled visit resolves false, which keeps the dialog open.

ts
const { put } = usePromiseRouter();

const save = (user: User) => put(`/users/${user.id}`, user);

Opening a component

A create flow does not need its dialog mounted on the page. Hand the directive a component instead of an id, with dialogProps for the dialog around it: the <BbHost /> the plugin renders mounts a fresh instance for that one opening and unmounts it after the close, so every open starts from a new setup and there is nothing to reset.

BugDesign

NewLabelForm is a plain component with no <BbDialog> of its own. It reads the dialog around it with useBbDialog(), no argument, and binds its form to the opening's data, a fresh copy of defaultData here. Create submits the form, and the label the save resolves is what onComplete gets. From code it is useBbDialog<In, Out>(NewLabelForm, { dialogProps }).show(data); with a record as data, the same component edits it.

  • Nothing to mount. The plugin's host renders it, as it renders confirms and toasts. Without the plugin the opening settles 'unmounted' after a second.
  • It takes the trigger's surroundings: a provide or a <BbConfigScope> around the button reaches the dialog, which paints in the host.
  • It lives as long as its opener. A route change or a row that re-renders away dismisses it ('unmounted').
  • One handle, one dialog. useBbDialog<In, Out>(NewLabelForm, { dialogProps }) is the same handle as the id form (isReady, open, data, show, hide, complete, reset), about its own dialog: a show() while it is open joins it. Another handle, or another trigger button, opens its own instance on top.
  • From a store. Create the handle in a setup store's body, then call show() from its actions or a router hook: the opening lives until it closes.

The dialog around it

dialogProps takes the dialog's look and footer props (title, description, size, fullscreen, adaptive, persistent, prevent-close, ok, cancel, actions and the rest), default-data and pt. A ref or a getter stays live. It never takes id (each opening gets its own), eager, navigation, query-key, replace or class.

  • The data arrives through useBbDialog(), never as props: the component gets no attributes from the opening. Outside any dialog the no-argument call returns a handle that does nothing (isReady false, show() settles 'missing'), and warns about nothing.
  • A dialog of its own when it is not standard. Header affixes, a custom footer or any other slot need the component to render its own <BbDialog id> with them. Open it with useBbDialog(Component) or v-bb-dialog="{ component }" and no dialogProps, and read it inside with the id form, useBbDialog('its-id').

Structure and size

The body is the only one of the three regions that scrolls: header and footer stay pinned.

The footer slot replaces the footer buttons with your own, here because Send waits for at least one recipient. Its scope carries close and complete, so Cancel needs no handle on the dialog. The footer lays the buttons out in a row at the end by itself, so they need no wrapper; class="me-auto" on one pushes it to the start. A footer with two primaries is a decision you have not made yet. Use the title slot when only the title text needs restyling. With neither a title nor a description the whole header goes, leaving the × floating over the top corner of the body. description adds one muted line under the title, and it is what screen readers read as the dialog's description. When that line needs markup, use the description slot.

Actions beside the title

To put a control beside the standard title, fill #header:append (after the title, before the ×) or #header:prepend (before it, for a back button only). The affixes and the × share one row on the title's line. The title, the description and the dialog's accessible name stay as they are.

Nothing downloaded yet.

  • Write icon-only size="md" variant="ghost". The affix never restyles your button, and that is the ×'s 28px box and colours. Write size even though md is the default, or an app-wide button size changes it.
  • A badge or a status is not an affix. Put it inline in the title slot.
  • An affix button takes the opening focus ahead of the ×. Point focus-target at the body when the task starts there.
  • hide-close removes only the ×. Two icon actions fit beside a phone-width title; a third belongs in a BbDropdown inside #header:append.

The header slot replaces the whole header, affixes and × included, on the dialog and on the mobile sheet alike.

Two things this slot makes yours. Render a control wired to the slot's close, because the default × is gone. And put titleId on your heading, or the dialog has no accessible name while the markup still looks correct. The description prop does not render inside a replaced header. Give your slot root flex-1: the header is a flex row, so a single child otherwise hugs the left edge.

Coming from v2

#close is gone, a custom close control lives inside #header. hideHeader is gone: omit title. compact, overlayClasses and panelClasses are gone too, since spacing is token-driven and the panel takes a normal class.

Never gate Cancel on validity: an unfinished form is exactly when someone wants out. A submit button of your own in the footer slot sits outside the <form> element: give the form an id and point the button at it with form="…" and type="submit", as Driving the form from outside shows.

Width and fullscreen

size is a maximum width: the height always hugs the content. Besides the presets it takes a pixel number or a CSS length.

The presets run from xs (320px) to 2xl (672px), and sm (384px) is the default. A per-breakpoint map, :size="{ default: 'xs', lg: 'xl' }", is the only form that reacts to a live resize.

Coming from v2preset widths

The preset values changed between v2 and v3 and nothing warns you. v2 shipped { sm: 384, md: 652, lg: 896 }, so a size="md" dialog now loses about 200px. Pin the old numbers if your layouts assumed them:

ts
// nuxt.config.ts
export default defineNuxtConfig({
    bitboss: { components: { BbDialog: { sizeMap: { md: 652, lg: 896 } } } },
});

fullscreen fills the viewport minus the standard page margin, intentionally not edge to edge. fullscreen="mobile" applies that only on small viewports.

Focus and the top layer

Focus, Escape and layering are the browser's job. There is nothing to wire, not even for a popover or a select opened from in here.

Focus is on: nothing yet, open one of the dialogs

focus-target is a CSS selector and decides only where focus starts. Without it the browser focuses the first tabbable element, and in a dialog with a header that is the ×. Point it at the field in a form, and at the primary action in a decision whose real content is its footer.

Focus returns to the trigger on close, as long as that trigger still exists. When the dialog's action destroys the row that opened it, focus drops to <body>, so move it somewhere sensible yourself.

The dialog paints above every z-index, and it stays where you declared it in the DOM. Scoped styles, provide/inject and your component tree all behave normally.

Steps in one dialog

ok belongs to the last step. Before it, give ok a Next button whose onClick moves on and returns false, so the dialog stays open; on the last step it is a plain label again, and submits the form.

vue
<BbDialog id="wizard" cancel :ok="step < 3 ? { text: 'Next', onClick: next } : 'Finish'">
ts
const step = ref(1);
const next = () => {
    step.value++;
    return false;
};
  • Give the form keep-values-on-unmount: steps shown with v-if unmount their fields, and without it each step's values leave data with them.
  • Each step's first field gets autofocus: it fires when the field mounts, so focus follows the step with no watcher (focus-target picks only where the opening starts).
  • A final success step with no field is a status region (role="status"), announced as it appears, not a focus target.

Controlling dismissal

persistent stops the backdrop and Escape from closing. The × still closes it: that is the deliberate escape hatch.

Backdrop and Escape play a nudge instead of closing.

On a form dialog, persistent="backdrop" is usually enough: a stray click outside cannot throw the input away, and Escape still closes.

Pair it with hide-close when the choice really has to be made, and then the footer owes the user a visible way out. persistent, hide-close and no Cancel is a trap in three directions: no Escape for the keyboard, no backdrop for the pointer, nothing for a screen reader to find.

While a save is in flight the dialog has to stay put, and a BbForm inside it does that by itself: return the save's promise from @submit and, until it settles, the fields turn read-only and the dialog refuses every close, the ×, Cancel, Escape and the backdrop, with the same nudge.

Project · vantera-storefront

No saving ref, no prevent-close, no :loading: ok submits the form, spins with the save and closes with what it resolved. complete() and the handle's hide() (or a v-model) close under the lock; cancel and the slots' close() do not.

prevent-close is for the rest. Unset, it follows the form. true refuses every user close, the × and the slots' close included, for work that is not a form submit. false keeps the dialog closable even mid-save, and disable-submit-lock on the form does the same.

Coming from v2show-close → hide-close

v2's show-close (default true) is v3's hide-close (default false), and the compiler cannot see it:

diff
- <BbDialog v-model="open" :show-close="false" persistent />
+ <BbDialog v-model="open" hide-close persistent />

A leftover :show-close="false" falls through to $attrs, and the close button comes back on the dialog that was deliberately built without one. eslint --fix rewrites it.

Stacks and mobile sheets

Dialogs that share a stack name replace one another instead of piling up.

Only the most recently opened member is visible, and closing it brings the previous one back. A two-step flow then reads as one surface whose content swaps. A member adds no dim of its own: the one it covers keeps its backdrop, so the page behind stays as dark as under the first member. Dialogs with different names layer by open order, each adding its dim (--bb-overlay-above; transparent keeps one dim under the whole pile).

Before you reuse the name on a phone: BbOffCanvas's stack does the opposite, with parents stepping back and leaving a band visible. An adaptive dialog forwards stack to its mobile sheet, so the same name gives you replacement on desktop and peeking on mobile. Override it through off-canvas-props.

The mobile bottom sheet

Below 768px this is not a centred modal: it renders as a BbOffCanvas bottom sheet. That is the shipped behaviour.

390px

:adaptive="false" keeps the centred modal everywhere, and components: { all: { adaptive: false } } in the plugin options does it project-wide.

The surface is latched when the dialog opens, so rotating a phone never swaps a modal for a sheet under someone's finger. snap-points and v-model:snap reach the sheet too (snap points).

The sheet starts bottom-anchored, draggable and content-sized. The dialog's own size is deliberately not forwarded: a max width and a drawer's extent are different measurements. Tune the sheet with off-canvas-props, which merges last:

vue
<BbDialog
    id="order-detail"
    :off-canvas-props="{ side: 'end', draggable: false, size: 'lg' }"
    title="Order detail"
/>

What you get on a phone is a real BbOffCanvas, so its rules apply there: the drag gesture, the peeking stack, and size meaning extent rather than width. The drawer page is where those live.

Padding and the title

Spacing reaches the dialog through --bb-panel-p (16px), split into the local pair --px and --py on .bb-dialog. Set them on the component's class, never on :root.

css
.my-dialog {
    --px: 24px;
    --py: 10px;
}

For per-part differences, scope --py to the part: .bb-dialog__header, .bb-dialog__content, .bb-dialog__footer. On a phone those parts are .bb-offcanvas__*.

To style both surfaces at once use pt (pt:header, pt:content, pt:footer…). It follows the dialog onto the sheet, and pt:sheet targets the phone only. Three more locals set the rhythm and the title for every dialog and sheet at once: --dialog-gap is the body-to-footer rhythm, --dialog-title-fs the title's size and --dialog-title-fw its weight (500).

css
.my-theme {
    --dialog-title-fw: 600;
}

BbOffCanvas uses the same names on its own parts.

The dialog takes the page's font and --bb-text, not the text styles of the element it is declared in; a class on the dialog or its content still wins.

Coming from v2--bb-dialog-close

Delete --bb-dialog-close rather than porting it. In v2 it was the close icon's width; in v3 --close-size (28px) is the whole control box, and the title reserves the same space beside it. A copied 12px then gives you a 12×12px target, under the 24px minimum in WCAG 2.5.8. The correct edit is usually none: v3 already ships the same 28px control v2 produced. The rest of the --bb-dialog-* family went with it: --bb-dialog-px and --bb-dialog-py are the --px and --py above, and everything else is plain CSS on the .bb-dialog__* parts.