Skip to content
THE COMPONENT LIBRARY
Skip to content

Component reference

Modal

A centered conversation that pauses the page until the user answers.

Preview

Live preview

Changes apply to this preview only.

Width adapts to the available space

More examples

Different configurations and compositions using the real Pimolu API. Each preview runs independently and follows the site appearance.

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.

Open preview

Enumerate the sm, md, lg and xl widths from modalVariantMap so the documentation and your application cannot drift apart.

Open preview

Apply local classes to stable named parts without replacing built-in states. Panel classes follow portalled content.

Open preview

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
PimoluModalProps public API
NameTypeDefaultDescription
childrenRequiredReactNode—Trigger, content, header, footer and close controls.
openboolean—Controlled open state. Omit to let the component own it.
defaultOpenbooleanfalseInitial open state when uncontrolled. Defaults to false.
onOpenChange((open: boolean) => void)—Called whenever the component asks to open or close.
childrenRequired

ReactNode

No default extracted.

Trigger, content, header, footer and close controls.

open

boolean

No default extracted.

Controlled open state. Omit to let the component own it.

defaultOpen

boolean

Default: 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
PimoluModalTriggerProps public API
NameTypeDefaultDescription
childrenRequiredReactElement<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.
tabIndexnumber—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.
childrenRequired

ReactElement<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.

tabIndex

number

No 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
PimoluModalContentProps public API
NameTypeDefaultDescription
childrenReactNode—Header, body and footer of the modal.
size"sm" | "md" | "lg" | "xl""md"Maximum width of the panel. Defaults to "md".
closeOnOverlayClickbooleantrueClose when the overlay is pressed. Defaults to true.
closeOnEscapebooleantrueClose on Escape. Defaults to true.
showCloseButtonbooleantrueRender the close button in the top corner. Defaults to true.
closeLabelstring"Close"Accessible name of the corner close button. Defaults to "Close".
aria-labelstring—Accessible name of the modal. Use it only when there is no `ModalTitle`; a title automatically names the modal.
aria-labelledbystring—Overrides the id registered by `ModalTitle`.
aria-describedbystring—Overrides the id registered by `ModalDescription`.
classNamestring—Class applied to the panel.
styleCSSProperties—Inline styles on the panel, including local CSS variables.
classNamesPimoluClassNames<"modal">—Additive classes on portalled parts; className still targets content. Named parts are listed in the Class names table.
children

ReactNode

No default extracted.

Header, body and footer of the modal.

size

"sm" | "md" | "lg" | "xl"

Default: "md"

Maximum width of the panel. Defaults to "md".

closeOnOverlayClick

boolean

Default: true

Close when the overlay is pressed. Defaults to true.

closeOnEscape

boolean

Default: true

Close on Escape. Defaults to true.

showCloseButton

boolean

Default: true

Render the close button in the top corner. Defaults to true.

closeLabel

string

Default: "Close"

Accessible name of the corner close button. Defaults to "Close".

aria-label

string

No default extracted.

Accessible name of the modal. Use it only when there is no `ModalTitle`; a title automatically names the modal.

aria-labelledby

string

No default extracted.

Overrides the id registered by `ModalTitle`.

aria-describedby

string

No default extracted.

Overrides the id registered by `ModalDescription`.

className

string

No default extracted.

Class applied to the panel.

style

CSSProperties

No default extracted.

Inline styles on the panel, including local CSS variables.

classNames

PimoluClassNames<"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
PimoluModalHeaderProps public API
NameTypeDefaultDescription
classNamesPimoluClassNames<"modal">—Additive classes for stable named parts, including composed descendants. Named parts are listed in the Class names table.
childrenRequiredReactNode—Public Pimolu prop; see the source declaration for details.
classNamestring—Public Pimolu prop; see the source declaration for details.
classNames

PimoluClassNames<"modal">

No default extracted.

Additive classes for stable named parts, including composed descendants. Named parts are listed in the Class names table.

childrenRequired

ReactNode

No default extracted.

Public Pimolu prop; see the source declaration for details.

className

string

No default extracted.

Public Pimolu prop; see the source declaration for details.

PimoluModalTitleProps

Type source
PimoluModalTitleProps public API
NameTypeDefaultDescription
classNamesPimoluClassNames<"modal">—Additive classes for stable named parts, including composed descendants. Named parts are listed in the Class names table.
childrenRequiredReactNode—Public Pimolu prop; see the source declaration for details.
idstring—Explicit id, instead of the generated one.
classNamestring—Public Pimolu prop; see the source declaration for details.
classNames

PimoluClassNames<"modal">

No default extracted.

Additive classes for stable named parts, including composed descendants. Named parts are listed in the Class names table.

childrenRequired

ReactNode

No default extracted.

Public Pimolu prop; see the source declaration for details.

id

string

No default extracted.

Explicit id, instead of the generated one.

className

string

No default extracted.

Public Pimolu prop; see the source declaration for details.

PimoluModalDescriptionProps

Type source
PimoluModalDescriptionProps public API
NameTypeDefaultDescription
classNamesPimoluClassNames<"modal">—Additive classes for stable named parts, including composed descendants. Named parts are listed in the Class names table.
childrenRequiredReactNode—Public Pimolu prop; see the source declaration for details.
idstring—Explicit id, instead of the generated one.
classNamestring—Public Pimolu prop; see the source declaration for details.
classNames

PimoluClassNames<"modal">

No default extracted.

Additive classes for stable named parts, including composed descendants. Named parts are listed in the Class names table.

childrenRequired

ReactNode

No default extracted.

Public Pimolu prop; see the source declaration for details.

id

string

No default extracted.

Explicit id, instead of the generated one.

className

string

No default extracted.

Public Pimolu prop; see the source declaration for details.

PimoluModalFooterProps

Type source
PimoluModalFooterProps public API
NameTypeDefaultDescription
classNamesPimoluClassNames<"modal">—Additive classes for stable named parts, including composed descendants. Named parts are listed in the Class names table.
childrenRequiredReactNode—Public Pimolu prop; see the source declaration for details.
classNamestring—Public Pimolu prop; see the source declaration for details.
classNames

PimoluClassNames<"modal">

No default extracted.

Additive classes for stable named parts, including composed descendants. Named parts are listed in the Class names table.

childrenRequired

ReactNode

No default extracted.

Public Pimolu prop; see the source declaration for details.

className

string

No default extracted.

Public Pimolu prop; see the source declaration for details.

PimoluModalCloseProps

Type source
PimoluModalCloseProps public API
NameTypeDefaultDescription
childrenRequiredReactElement<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.
childrenRequired

ReactElement<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 parts

Pass 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.

  • closeButton
  • content
  • description
  • footer
  • header
  • overlay
  • root
  • title

CSS variables

20 variables

Custom 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.
Read the accessibility guide →