|Kit

Modal

Centered overlay dialog on Ark UI's Dialog machine — focus trap, scroll lock, RTL and animated enter/exit, with a flat props API and composable parts.

The Modal is a centered overlay built on Ark UI's Dialog state machine. Ark owns focus-trapping, body scroll-lock, RTL, the Esc / click-outside behaviour and the data-state attribute that drives the enter/exit animations; the kit adds a flat props API plus styled, composable parts.

import { Modal } from '@42-central/ui-react/modal';

<Modal open={open} onOpenChange={setOpen} title="Welcome">
  <Text>Anything you like in the body.</Text>
</Modal>

To spawn modals imperatively — without useState at every call site — use the overlays manager.

Basic usage

open / onOpenChange make the modal a controlled component. onOpenChange is flattened to (open: boolean) => void.

Code

const [open, setOpen] = useState(false);

<Button onClick={() => setOpen(true)}>Open modal</Button>
<Modal open={open} onOpenChange={setOpen} title="Welcome aboard">
  <Text>Focus is trapped and the page is scroll-locked while open.</Text>
</Modal>

Sizes

size maps to the kit's width tokens (xs–xl), plus full for a near-fullscreen sheet.

Code

<Modal size="sm" … />
<Modal size="md" … />  // default
<Modal size="lg" … />
<Modal size="xl" … />

Centered

By default the modal anchors near the top of the viewport (so tall content grows downward). Set centered to vertically center it.

Code

<Modal centered title="Centered" … />

Description & close button

title and description render the header; withCloseButton (default true) adds a dogfooded ActionIcon close button.

Code

<Modal
  title="Delete file"
  description="This action cannot be undone."
  withCloseButton={false}
/>

Icons

icons replaces the kit's icons. Modal has one, close, for the header's close button. It sits on the ready-made Modal and on Modal.Root, where Modal.CloseTrigger reads it; a Modal.CloseTrigger's own children win over it. A missing key keeps its default. To drop the button, set withCloseButton={false} rather than a null icon, which would leave an empty button. Your icons are drawn as given: add className={iconStroke} (from @42/ui-react) for the kit's 1.5px line.

Code

<Modal title="Custom icon" icons={{ close: <CircleXIcon className={iconStroke} /> }} … />

Composable parts

The high-level <Modal> covers the common case. For full control over structure, compose the parts directly — they carry the same styling and Ark wiring:

<Modal.Root open={open} onOpenChange={({ open }) => setOpen(open)}>
  <Modal.Trigger asChild>
    <Button>Open</Button>
  </Modal.Trigger>
  <Modal.Backdrop />
  <Modal.Positioner position="center">
    <Modal.Content size="md">
      <Modal.Header>
        <Modal.Title>Custom layout</Modal.Title>
        <Modal.CloseTrigger />
      </Modal.Header>
      <Modal.Body>…</Modal.Body>
      <Modal.Footer>
        <Button>Cancel</Button>
        <Button>Save</Button>
      </Modal.Footer>
    </Modal.Content>
  </Modal.Positioner>
</Modal.Root>

Modal.Body is a vertical ScrollArea that takes the space between the header and the footer. Its className (and its other props) land on the scrolled content, where the padding and the children's layout live, so className="flex flex-col gap-4" or p-0 work as you'd expect. When the content owns its own scroller (a list with its own height, a header that must stay put), pass scrollable={false}, on Modal.Body or on the ready-made Modal: the body becomes a plain column that takes the space left and lets that scroller shrink (min-h-0), so a short screen shrinks your list instead of scrolling the whole body. Spotlight does this.

Modal.Root, Modal.Trigger, and Modal.Context are raw Ark re-exports with no DOM node (or styling) of their own, so none take a testId. Modal.Backdrop, Modal.Positioner, Modal.Content, Modal.Title, Modal.Description, Modal.Header, Modal.Body, and Modal.Footer each take their own testId, landing on their own rendered element. Modal.CloseTrigger's testId routes to the actual rendered close button — an inner ActionIcon, since CloseTrigger itself is asChild over it. See Testing.

API

Prop

Type

All other props (modal, trapFocus, preventScroll, id, lazyMount, …) forward to Ark's Dialog.Root.

Accessibility

  • Ark traps focus inside the content while open and restores it to the trigger on close.
  • The body is scroll-locked (preventScroll) and content below is hidden from assistive tech (modal).
  • title wires aria-labelledby and description wires aria-describedby automatically. When you omit a title, render a Modal.Title inside it (visually hidden with sr-only if need be), or pass an aria-label or aria-labelledby. A modal with none of these has no accessible name, and the kit warns in the console during development.
  • Animations collapse to a 1ms opacity tween under prefers-reduced-motion.

Changelog

v0.30.0
  • Modal.Body and Drawer.Body scroll in a ScrollArea, and className lands on the scrolled content: to turn the body's scroll off, pass scrollable={false} instead of overflow-hidden

    #494
  • scrollable={false} on Modal, Drawer and their Body gives a plain body for content that has its own scroller

    #494
v0.20.0
  • Swap any built-in icon through an icons map — icons={{ asc, desc }} on DataTable, icons={{ show, hide }} on PasswordInput; a key you leave out keeps the kit's icon, and a part's children still win

    #361
  • Drawer, Modal and AppShell.Sidebar accept aria-label/aria-labelledby, and development warns when an open dialog has no accessible name

    #383
  • An open Modal or Drawer is a hotkey layer: hotkeys under it go quiet, and a Popover it was opened from stays open

    #396
  • classNames.positioner can override the positioner's overflow-clip

    #383
v0.19.0
  • A translations prop for the close, dismiss, collapse/expand and region labels; <Notifications /> forwards its keys to every toast

    #331
v0.18.0
  • asChild is a compile error on Combobox.Control, Group, Content, Panel and Item, Drawer/Modal.Positioner, Drawer.Grabber, Popover.Content and Tooltip.Arrow

    #294
  • CloseTrigger asChild uses your element in place of the icon button, without the forced aria-label

    #288
v0.16.0
  • An outside click no longer dismisses the parent while a nested overlay is open

    #251
v0.9.0
  • --modal-z rises from 50 to 150, leaving room for the toast band below it

    #135
v0.4.0
  • Floating surfaces take a brand tint

    #41
v0.3.0
  • Panels and highlights use translucent washes instead of opaque grays

    #35
v0.0.1
  • Modal and Drawer, controlled by open/onOpenChange; Drawer slides in from any edge

On this page