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). titlewiresaria-labelledbyanddescriptionwiresaria-describedbyautomatically. When you omit atitle, render aModal.Titleinside it (visually hidden withsr-onlyif need be), or pass anaria-labeloraria-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
- #361
Swap any built-in icon through an
iconsmap —icons={{ asc, desc }}on DataTable,icons={{ show, hide }}on PasswordInput; a key you leave out keeps the kit's icon, and a part'schildrenstill win - #383
Drawer, Modal and
AppShell.Sidebaracceptaria-label/aria-labelledby, and development warns when an open dialog has no accessible name - #396
An open Modal or Drawer is a hotkey layer: hotkeys under it go quiet, and a Popover it was opened from stays open
- #383
classNames.positionercan override the positioner'soverflow-clip
- #331
A
translationsprop for the close, dismiss, collapse/expand and region labels;<Notifications />forwards its keys to every toast
- #251
An outside click no longer dismisses the parent while a nested overlay is open
- #135
--modal-zrises from 50 to 150, leaving room for the toast band below it
- #41
Floating surfaces take a brand tint
- #35
Panels and highlights use translucent washes instead of opaque grays
ModalandDrawer, controlled byopen/onOpenChange; Drawer slides in from any edge
HoverCard
A rich preview panel on Ark UI's HoverCard — delayed, portaled and animated. Hover a trigger, see a card; add HoverCard.Group so a row of triggers shares one card that slides between them.
Drawer
Edge-anchored panel on Ark UI's Drawer machine — swipe-to-dismiss, snap points and a drag grabber, with an RTL-aware placement prop.