Dialog v0.1.0 Overlay

Modal dialog driven by a core state machine; focus trap, scroll lock, Escape and backdrop dismissal handled automatically.

import { Dialog, useDialog } from "latticeui-react";

Examples

Confirmation dialog

Focus is trapped, scroll is locked, Escape and the backdrop dismiss.

Show code
<Dialog.Root>
  <Dialog.Trigger>Delete workspace</Dialog.Trigger>
  <Dialog.Content>
    <Dialog.Title>Delete workspace?</Dialog.Title>
    <Dialog.Description>
      This permanently deletes the workspace and all of its data.
    </Dialog.Description>
    <Button variant="danger">Delete</Button>
    <Dialog.Close />
  </Dialog.Content>
</Dialog.Root>

Anatomy

These data-part attributes are a versioned public API - style and test against them; they will not change in a minor release.

PartElementStable selector
triggerbutton[data-scope="dialog"][data-part="trigger"]
backdropdiv[data-scope="dialog"][data-part="backdrop"]
positionerdiv[data-scope="dialog"][data-part="positioner"]
contentdiv[role=dialog][data-scope="dialog"][data-part="content"]
titleh2[data-scope="dialog"][data-part="title"]
descriptionp[data-scope="dialog"][data-part="description"]
closebutton[data-scope="dialog"][data-part="close"]

Props

PropTypeDefaultDescription
Root.open / defaultOpenbooleanControlled / uncontrolled.
Root.onOpenChange(open: boolean) => void
Content.closeOnOutsideClickbooleantrue

Accessibility

Roles: dialog with aria-modal

KeyAction
Escapecloses
Tabcycles within the dialog (focus trap)

Styling

Override styles by targeting the stable selectors below from any unlayered CSS - it always beats the library's @layer latticeui styles, no !important needed.

[data-scope="dialog"][data-part="content"] {
  /* your overrides */
}

State attributes: data-state=open