Skip to content
Nana UI

Dialog

View .md Download

A modal dialog built on the native <dialog> element — so it gets the top layer, a backdrop, focus trapping and Escape-to-close for free. Compose it from nana-dialog-header, nana-dialog-body and nana-dialog-footer.

Set the open attribute or call show() to display it.
Terminal window
npm install @nana-tec/ui-components
import "@nana-tec/ui-components/dialog";
<nana-dialog label="Dialog" open>
Set the <code>open</code> attribute or call <code>show()</code> to display it.
</nana-dialog>

Compose the dialog with nana-dialog-header, nana-dialog-body, and nana-dialog-footer. Open it with the open attribute, .show(), or a data-open="#id" trigger; close with data-close.

<nana-button data-open="#invite">Invite teammate</nana-button>
<nana-dialog id="invite" aria-label="Invite teammate">
<nana-dialog-header>Invite teammate</nana-dialog-header>
<nana-dialog-body>
<nana-input label="Email" type="email" placeholder="ada@example.com"></nana-input>
</nana-dialog-body>
<nana-dialog-footer>
<nana-button variant="ghost" data-close>Cancel</nana-button>
<nana-button variant="primary" data-close>Send invite</nana-button>
</nana-dialog-footer>
</nana-dialog>

Set variant (modal, alert, drawer, fullscreen) and size (xsxl, fullscreen). Use placement="start|end" for the drawer variant.

<nana-dialog variant="alert" size="sm" aria-label="Delete project"></nana-dialog>
<nana-dialog variant="drawer" placement="end" aria-label="Settings"></nana-dialog>
<nana-dialog variant="fullscreen" aria-label="Editor"></nana-dialog>

Properties

PropertyAttributeTypeDefaultDescription
ariaLabelaria-labelstring | nullnullAccessible label (use when there is no visible heading)
noBackdropCloseno-backdrop-closebooleanfalseDon't close when the backdrop is clicked
noEscapeCloseno-escape-closebooleanfalseDon't close when Escape is pressed
openbooleanfalseWhether the dialog is open
placementDialogPlacement'end'Which edge a drawer slides from
sizeDialogSize'md'Panel size
variantDialogVariant'modal'Behaviour / placement style

Events

EventDescription
nana-openFired after the dialog opens
nana-closeFired after the dialog closes (`detail.returnValue`)

Slots

SlotDescription
(default)Dialog content (header / body / footer)

CSS parts

PartDescription
::part(dialog)The native `<dialog>` element
::part(panel)The content surface

CSS custom properties

PropertyDescription
--nana-dialog-widthPanel width (per size by default)
--nana-dialog-backdropBackdrop colour
--nana-dialog-radiusPanel corner radius
EventTypeDescription
nana-openCustomEventFired after the dialog opens
nana-closeCustomEventFired after the dialog closes (detail.returnValue)
SlotDescription
(default)Dialog content (header / body / footer)
VariableDefaultDescription
--nana-dialog-widthPanel width (per size by default)
--nana-dialog-backdropBackdrop colour
--nana-dialog-radiusPanel corner radius
PartDescription
dialogThe native <dialog> element
panelThe content surface
  • Keyboard accessible
  • Screen-reader labels
  • Focus-visible states
  • ARIA roles and states
  • WCAG 2.2 AA contrast
Explore Dialog interactively Every state, prop, and edge case — with live controls — in Storybook.
View in Storybook