suiss/ui · Pattern
Modal
A modal window that opens as a centered dialog on desktop and a bottom drawer on mobile.
Modal is an open-source pattern from suiss/ui for React. The @esuiss/ui CLI copies its source into your project, so you own the code.
Modal presents focused content that blocks the rest of the page, such as a form or a share sheet. On desktop it renders a Dialog. Below the 48rem breakpoint it renders a bottom Drawer with a swipe handle, and each part switches to its drawer counterpart: the header, title, description and close map to the drawer's parts, ModalBody gains padding, and ModalFooter stacks its buttons in reverse order so the primary action sits on top.
Use it for tasks that need the user's full attention before returning to the page.
Installation
CLI
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Manual
-
Add the
cnhelper. -
Copy the source into
components/patterns/modal.tsx:
- Update the import paths to match your project.
Usage
ModalContent shows a close button by default; set showCloseButton to false to hide it, or pass closeLabel to show text instead of the icon.
The modal can be controlled with open and onOpenChange or uncontrolled with defaultOpen. Pass render to ModalTrigger or ModalClose to use your own Button.
The modal can be controlled with open and onOpenChange or uncontrolled with defaultOpen. Set asChild on ModalTrigger or ModalClose to use your own Button.
Examples
With close button
Relies on the default corner close button as the only way to dismiss besides Escape.
With close label
Replaces the close icon with a text button using closeLabel.
Floating
Insets the mobile drawer from the screen edges with floating.
API Reference
Modal
The root that renders a Dialog on desktop and a Drawer on mobile.
| Prop | Type | Default | Description |
|---|---|---|---|
onOpenChange | (open: boolean) => void | - | Called when the modal opens or closes. |
floating | boolean | - | Insets the mobile drawer from the screen edges with fully rounded corners. |
Also accepts the props of React.ComponentProps<typeof Dialog>.
ModalTrigger
The button that opens the modal.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Classes applied to the trigger. |
Also accepts the props of React.ComponentProps<typeof DialogTrigger>.
ModalContent
The popup window, with a close button by default.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Classes applied to the dialog or drawer popup. |
style | React.CSSProperties | - | Inline styles applied to the dialog or drawer popup. |
Also accepts the props of React.ComponentProps<typeof DialogContent>.
ModalHeader
Groups the title and description.
Also accepts the props of React.ComponentProps<"div">.
ModalBody
The main content area, padded on mobile.
Also accepts the props of React.ComponentProps<"div">.
ModalFooter
Holds the modal's actions; stacked with the primary action on top on mobile.
Also accepts the props of React.ComponentProps<"div">.
ModalTitle
The modal's title, used as its accessible name.
Also accepts the props of React.ComponentProps<typeof DialogTitle>.
ModalDescription
Supporting text, used as the modal's accessible description.
Also accepts the props of React.ComponentProps<typeof DialogDescription>.
ModalClose
A button that closes the modal.
Also accepts the props of React.ComponentProps<typeof DialogClose>.
Accessibility
- The popup has the
dialogrole, named byModalTitleand described byModalDescription. Escapecloses the modal and returns focus to the trigger.- The default close button is labelled Close.
Notes
Parts carry data-slot values from modal through modal-close. ModalContent accepts className and style as plain values only, because the same props are forwarded to either the dialog or the drawer popup.