Component reference
Modal
A centered conversation that pauses the page until the user answers.
Preview
Live previewOptional six-digit hex. Clear to restore the preset. Check contrast with your brand color.
Changes apply to this preview only.
Width adapts to the available space
"use client";
import {
Button,
Modal,
ModalClose,
ModalContent,
ModalDescription,
ModalFooter,
ModalHeader,
ModalTitle,
ModalTrigger,
} from "@pimolu/react";
export function DemoExample() {
return (
<Modal>
<ModalTrigger>
<Button>Share the project</Button>
</ModalTrigger>
<ModalContent size="sm">
<ModalHeader>
<ModalTitle>Share Project Atlas</ModalTitle>
<ModalDescription>
Invite a teammate to review the migration plan before Friday.
</ModalDescription>
</ModalHeader>
<p>
They receive an email with a link to the project. You can change
their role at any time.
</p>
<ModalFooter>
<ModalClose>
<Button appearance="outline" variant="neutral">Not now</Button>
</ModalClose>
<ModalClose>
<Button>Send invite</Button>
</ModalClose>
</ModalFooter>
</ModalContent>
</Modal>
);
}More examples
Different configurations and compositions using the real Pimolu API. Each preview runs independently and follows the site appearance.
Triggers, focus and dismissal
A non-focusable span trigger receives tabIndex and a button role. Focus moves inside the panel, Tab stays contained and Escape returns it to the trigger. Source workspace addition; not yet published on npm.
Sizes
Enumerate the sm, md, lg and xl widths from modalVariantMap so the documentation and your application cannot drift apart.
Named-part customization
Apply local classes to stable named parts without replacing built-in states. Panel classes follow portalled content.
Usage
Compose ModalTrigger and ModalContent with a title and description. Size caps the panel from sm to xl; Dialog remains the lighter name for the same interaction in existing applications.
Use open/onOpenChange when your workflow owns dismissal. ModalClose wraps an existing button without creating a nested button, and a non-focusable trigger child receives tabIndex and a button role automatically.
Available since 0.1.0-beta.9: the Modal family installs from the published packages.
API reference
Generated from the public TypeScript declarations. Native HTML attributes are inherited where the component extends them; this reference includes Pimolu props and selected common native attributes.
PimoluModalProps
Type source| Name | Type | Default | Description |
|---|---|---|---|
childrenRequired | ReactNode | — | Trigger, content, header, footer and close controls. |
open | boolean | — | Controlled open state. Omit to let the component own it. |
defaultOpen | boolean | false | Initial open state when uncontrolled. Defaults to false. |
onOpenChange | ((open: boolean) => void) | — | Called whenever the component asks to open or close. |
childrenRequiredReactNodeNo default extracted.
Trigger, content, header, footer and close controls.
openbooleanNo default extracted.
Controlled open state. Omit to let the component own it.
defaultOpenbooleanDefault: false
Initial open state when uncontrolled. Defaults to false.
onOpenChange((open: boolean) => void)No default extracted.
Called whenever the component asks to open or close.
PimoluModalTriggerProps
Type source| Name | Type | Default | Description |
|---|---|---|---|
childrenRequired | ReactElement<unknown, string | JSXElementConstructor<any>> | — | The element that opens the modal: any element, or a component that passes down the props it receives. It gets the ARIA state, the click handler and the ref, and the handlers it already had keep working. |
tabIndex | number | — | Tab index forwarded to the cloned trigger. When the element is not natively focusable and no value is given, Pimolu adds `tabIndex={0}` and `role="button"` so keyboard users can reach it. |
childrenRequiredReactElement<unknown, string | JSXElementConstructor<any>>No default extracted.
The element that opens the modal: any element, or a component that passes down the props it receives. It gets the ARIA state, the click handler and the ref, and the handlers it already had keep working.
tabIndexnumberNo default extracted.
Tab index forwarded to the cloned trigger. When the element is not natively focusable and no value is given, Pimolu adds `tabIndex={0}` and `role="button"` so keyboard users can reach it.
PimoluModalContentProps
Type source| Name | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Header, body and footer of the modal. |
size | "sm" | "md" | "lg" | "xl" | "md" | Maximum width of the panel. Defaults to "md". |
closeOnOverlayClick | boolean | true | Close when the overlay is pressed. Defaults to true. |
closeOnEscape | boolean | true | Close on Escape. Defaults to true. |
showCloseButton | boolean | true | Render the close button in the top corner. Defaults to true. |
closeLabel | string | "Close" | Accessible name of the corner close button. Defaults to "Close". |
aria-label | string | — | Accessible name of the modal. Use it only when there is no `ModalTitle`; a title automatically names the modal. |
aria-labelledby | string | — | Overrides the id registered by `ModalTitle`. |
aria-describedby | string | — | Overrides the id registered by `ModalDescription`. |
className | string | — | Class applied to the panel. |
style | CSSProperties | — | Inline styles on the panel, including local CSS variables. |
classNames | PimoluClassNames<"modal"> | — | Additive classes on portalled parts; className still targets content. Named parts are listed in the Class names table. |
childrenReactNodeNo default extracted.
Header, body and footer of the modal.
size"sm" | "md" | "lg" | "xl"Default: "md"
Maximum width of the panel. Defaults to "md".
closeOnOverlayClickbooleanDefault: true
Close when the overlay is pressed. Defaults to true.
closeOnEscapebooleanDefault: true
Close on Escape. Defaults to true.
showCloseButtonbooleanDefault: true
Render the close button in the top corner. Defaults to true.
closeLabelstringDefault: "Close"
Accessible name of the corner close button. Defaults to "Close".
aria-labelstringNo default extracted.
Accessible name of the modal. Use it only when there is no `ModalTitle`; a title automatically names the modal.
aria-labelledbystringNo default extracted.
Overrides the id registered by `ModalTitle`.
aria-describedbystringNo default extracted.
Overrides the id registered by `ModalDescription`.
classNamestringNo default extracted.
Class applied to the panel.
styleCSSPropertiesNo default extracted.
Inline styles on the panel, including local CSS variables.
classNamesPimoluClassNames<"modal">No default extracted.
Additive classes on portalled parts; className still targets content. Named parts are listed in the Class names table.
PimoluModalHeaderProps
Type source| Name | Type | Default | Description |
|---|---|---|---|
classNames | PimoluClassNames<"modal"> | — | Additive classes for stable named parts, including composed descendants. Named parts are listed in the Class names table. |
childrenRequired | ReactNode | — | Public Pimolu prop; see the source declaration for details. |
className | string | — | Public Pimolu prop; see the source declaration for details. |
classNamesPimoluClassNames<"modal">No default extracted.
Additive classes for stable named parts, including composed descendants. Named parts are listed in the Class names table.
childrenRequiredReactNodeNo default extracted.
Public Pimolu prop; see the source declaration for details.
classNamestringNo default extracted.
Public Pimolu prop; see the source declaration for details.
PimoluModalTitleProps
Type source| Name | Type | Default | Description |
|---|---|---|---|
classNames | PimoluClassNames<"modal"> | — | Additive classes for stable named parts, including composed descendants. Named parts are listed in the Class names table. |
childrenRequired | ReactNode | — | Public Pimolu prop; see the source declaration for details. |
id | string | — | Explicit id, instead of the generated one. |
className | string | — | Public Pimolu prop; see the source declaration for details. |
classNamesPimoluClassNames<"modal">No default extracted.
Additive classes for stable named parts, including composed descendants. Named parts are listed in the Class names table.
childrenRequiredReactNodeNo default extracted.
Public Pimolu prop; see the source declaration for details.
idstringNo default extracted.
Explicit id, instead of the generated one.
classNamestringNo default extracted.
Public Pimolu prop; see the source declaration for details.
PimoluModalDescriptionProps
Type source| Name | Type | Default | Description |
|---|---|---|---|
classNames | PimoluClassNames<"modal"> | — | Additive classes for stable named parts, including composed descendants. Named parts are listed in the Class names table. |
childrenRequired | ReactNode | — | Public Pimolu prop; see the source declaration for details. |
id | string | — | Explicit id, instead of the generated one. |
className | string | — | Public Pimolu prop; see the source declaration for details. |
classNamesPimoluClassNames<"modal">No default extracted.
Additive classes for stable named parts, including composed descendants. Named parts are listed in the Class names table.
childrenRequiredReactNodeNo default extracted.
Public Pimolu prop; see the source declaration for details.
idstringNo default extracted.
Explicit id, instead of the generated one.
classNamestringNo default extracted.
Public Pimolu prop; see the source declaration for details.
PimoluModalFooterProps
Type source| Name | Type | Default | Description |
|---|---|---|---|
classNames | PimoluClassNames<"modal"> | — | Additive classes for stable named parts, including composed descendants. Named parts are listed in the Class names table. |
childrenRequired | ReactNode | — | Public Pimolu prop; see the source declaration for details. |
className | string | — | Public Pimolu prop; see the source declaration for details. |
classNamesPimoluClassNames<"modal">No default extracted.
Additive classes for stable named parts, including composed descendants. Named parts are listed in the Class names table.
childrenRequiredReactNodeNo default extracted.
Public Pimolu prop; see the source declaration for details.
classNamestringNo default extracted.
Public Pimolu prop; see the source declaration for details.
PimoluModalCloseProps
Type source| Name | Type | Default | Description |
|---|---|---|---|
childrenRequired | ReactElement<unknown, string | JSXElementConstructor<any>> | — | The element that closes the modal: any element, or a component that passes down the props it receives. Its own click handler still runs. |
childrenRequiredReactElement<unknown, string | JSXElementConstructor<any>>No default extracted.
The element that closes the modal: any element, or a component that passes down the props it receives. Its own click handler still runs.
Class names
8 partsPass these keys to classNames to style the matching element. A part renders only when its element or state is present; keys are additive and never replace the component class.
closeButtoncontentdescriptionfooterheaderoverlayroottitle
CSS variables
20 variablesCustom properties read by this component's shared stylesheet. Set them on the component, an ancestor or :root; they fall back to the theme when unset.
--pimolu-background--pimolu-border--pimolu-control-border-width--pimolu-focus-ring--pimolu-font-body--pimolu-font-heading--pimolu-foreground--pimolu-glass-blur--pimolu-modal-width--pimolu-muted--pimolu-muted-foreground--pimolu-radius-lg--pimolu-radius-sm--pimolu-shadow-raised--pimolu-spacing-3--pimolu-spacing-4--pimolu-spacing-6--pimolu-spacing-8--pimolu-surface--pimolu-surface-foreground
Accessibility
- Use ModalTitle to name the panel and ModalDescription for context. Focus is trapped, Escape and the overlay dismiss by default, the page cannot scroll behind the panel, and focus returns to the trigger.
- Keep a visible or programmatic close path when Escape and overlay dismissal are disabled. Once the modal closes, its controls become inactive during the exit animation.
- Since beta.8: automatic focus and keyboard loops skip controls hidden with CSS or hidden/inert ancestors, as well as disabled controls. Visibility is rechecked at each navigation; style lookups are shared only within that traversal, so later changes take effect immediately. Menu arrow navigation still reaches enabled items with roving tabIndex. Keep an accessible close action or Escape available when conditionally hiding actions.