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.
Use it for tasks that need the user's full attention before returning to the page.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Usage
Composition
Use the following composition to build a Modal:
Examples
With close button
ModalContent shows a corner close button by default; here it is the only way to dismiss besides Escape. Set showCloseButton to false to hide it.
With close label
Set closeLabel to show a text button instead of the close icon.
Floating
Set floating to inset the mobile drawer from the screen edges with fully rounded corners.
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.
API Reference
Modal
The root that renders a Dialog on desktop and a Drawer on mobile.
| Prop | Type | Default |
|---|---|---|
open | boolean | - |
defaultOpen | boolean | - |
onOpenChange | (open: boolean) => void | - |
floating | boolean | - |
children | React.ReactNode | - |
The modal can be controlled with open and onOpenChange or uncontrolled with defaultOpen.
ModalTrigger
The button that opens the modal.
| Prop | Type | Default |
|---|---|---|
className | string | - |
Also accepts the props of React.ComponentProps<typeof DialogTrigger>.
Also accepts className, children, id and aria-label.
Pass render to replace the button with your own element, such as a Button.
Set asChild to use your own element, such as a Button.
ModalContent
The popup window, with a close button by default.
| Prop | Type | Default |
|---|---|---|
className | string | - |
style | React.CSSProperties | - |
Also accepts the props of React.ComponentProps<typeof DialogContent>.
Also accepts showCloseButton, closeLabel, children, id and aria-label.
className and style apply to the dialog or drawer popup. They are plain values only, because the same props are forwarded to either popup.
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">.
On mobile it stacks its buttons in reverse order so the primary action sits on top.
ModalTitle
The modal's title, used as its accessible name.
Also accepts the props of React.ComponentProps<typeof DialogTitle>.
Also accepts className, children and id.
ModalDescription
Supporting text, used as the modal's accessible description.
Also accepts the props of React.ComponentProps<typeof DialogDescription>.
Also accepts className, children and id.
ModalClose
A button that closes the modal.
Also accepts the props of React.ComponentProps<typeof DialogClose>.
Also accepts className, children, id and aria-label.
Pass render to replace the button with your own element, such as a Button.
Set asChild to use your own element, such as a Button.
Each part sets a data-slot, such as modal-content or modal-close, for styling.