PeakUI

Modal

Modal dialog overlay for focused interactions

Usage

import {Modal} from "@peakui/react";

Anatomy

import {Button, Modal} from "@peakui/react";

export default () => (
  <Modal>
    <Button>Open modal</Button>
    <Modal.Backdrop>
      <Modal.Container>
        <Modal.Dialog>
          <Modal.CloseTrigger /> {/* Optional: close button */}
          <Modal.Header>
            <Modal.Icon /> {/* Optional: icon */}
            <Modal.Heading />
          </Modal.Header>
          <Modal.Body />
          <Modal.Footer />
        </Modal.Dialog>
      </Modal.Container>
    </Modal.Backdrop>
  </Modal>
);

Examples

Sizes

Placement

Scroll Behavior

Controlled State

With Form

Custom Triggers

Backdrop Variants

Custom Backdrop

Dismiss Behavior

Close Methods

Custom Animations

Custom Portal

Customization

Tailwind CSS

Global CSS

@layer components {
  .modal__backdrop {
    @apply bg-linear-to-br from-black/50 to-black/70;
  }

  .modal__dialog {
    @apply rounded-2xl border border-white/10 shadow-2xl;
  }

  .modal__header {
    @apply text-center;
  }
}

Styling Reference

PeakUI follows the BEM methodology, so variants and states are plain class names you can target.

CSS Classes

The Modal component uses these CSS classes (view source styles):

Base & Element Classes

  • .modal__trigger - Trigger element that opens the modal
  • .modal__backdrop - Overlay backdrop behind the modal
  • .modal__container - Positioning wrapper with placement support
  • .modal__dialog - Modal content container
  • .modal__header - Header section for titles and icons
  • .modal__heading - Heading element styles
  • .modal__icon - Optional icon indicator
  • .modal__body - Main content area
  • .modal__footer - Footer section for actions
  • .modal__close-trigger - Close button position styles

Backdrop Variant Classes

  • .modal__backdrop--opaque - Opaque dimmed backdrop (default)
  • .modal__backdrop--blur - Blurred backdrop
  • .modal__backdrop--transparent - Transparent backdrop

Scroll Variant Classes

  • .modal__dialog--scroll-inside - Constrains the dialog for body scrolling
  • .modal__dialog--scroll-outside - Lets the backdrop scroll the dialog
  • .modal__container--scroll-outside - Moves scrolling to the backdrop
  • .modal__body--scroll-inside - Makes only the body scrollable
  • .modal__body--scroll-outside - Allows full-page scrolling

Size Classes

  • .modal__dialog--xs
  • .modal__dialog--sm
  • .modal__dialog--md
  • .modal__dialog--lg
  • .modal__dialog--cover - Full screen with margins
  • .modal__container--full - Fullscreen container without padding
  • .modal__dialog--full - Fullscreen dialog without radius or shadow

Slots

  • [data-slot="modal-trigger"] - The Modal.Trigger element
  • [data-slot="modal-backdrop"] - The Modal.Backdrop overlay
  • [data-slot="modal-container"] - The Modal.Container positioning wrapper
  • [data-slot="modal-dialog"] - The Modal.Dialog element
  • [data-slot="modal-header"] - The Modal.Header element
  • [data-slot="modal-icon"] - The Modal.Icon element
  • [data-slot="modal-heading"] - The Modal.Heading element
  • [data-slot="modal-body"] - The Modal.Body element
  • [data-slot="modal-footer"] - The Modal.Footer element
  • [data-slot="modal-close-trigger"] - The Modal.CloseTrigger element; it renames CloseButton's slot through the typed data-slot prop

Interactive States

The overlay parts carry React Aria animation states:

  • Entering: [data-entering="true"]
  • Exiting: [data-exiting="true"]
  • Placement: [data-placement="auto | top | center | bottom"] on container and dialog

The trigger supports both pseudo-classes and data attributes:

  • Focus: :focus-visible or [data-focus-visible="true"]
  • Disabled: :disabled or [aria-disabled="true"]
  • Pressed: :active or [data-pressed="true"]

API Reference

PropTypeDefaultDescription
childrenReact.ReactNode-The trigger element followed by the overlay
stateUseOverlayStateReturn-Overlay state from useOverlayState()
...restDialogTriggerProps-React Aria DialogTrigger attributes

Modal.Trigger

PropTypeDefaultDescription
childrenReact.ReactNode-Non-interactive element to make pressable
classNamestring-Additional classes
renderDOMRenderFunction<E, undefined>-Replaces the rendered <div>; E defaults to 'div'
...restHTMLAttributes-The attributes of the rendered element

Modal.Backdrop

PropTypeDefaultDescription
variant"opaque" | "blur" | "transparent""opaque"Backdrop overlay style
isDismissablebooleantrueClose on backdrop interaction
isKeyboardDismissDisabledbooleanfalseDisable the Escape key
isOpenboolean-Controlled open state
defaultOpenbooleanfalseInitially open, without controlling
onOpenChange(isOpen: boolean) => void-Open state change handler
UNSTABLE_portalContainerHTMLElement-Custom portal container
classNamestring | ((renderProps) => string)-Additional classes, or a function of the state
...restModalOverlayProps-React Aria ModalOverlay attributes

Modal.Container

PropTypeDefaultDescription
placement"auto" | "top" | "center" | "bottom""auto"Position on screen
scroll"inside" | "outside""inside"Scroll behavior
size"xs" | "sm" | "md" | "lg" | "cover" | "full""md"Size variant
classNamestring | ((renderProps) => string)-Additional classes, or a function of the state
...restModalProps-React Aria Modal attributes

Modal.Dialog

PropTypeDefaultDescription
childrenReact.ReactNode | (({close}) => React.ReactNode)-Content, or a function receiving close
role"dialog" | "alertdialog""dialog"ARIA role
aria-labelstring-Accessible name when no Modal.Heading is present
aria-labelledbystring-ID of the labelling element; set from Modal.Heading
aria-describedbystring-ID of the describing element
classNamestring-Additional classes
...restDialogProps-React Aria Dialog attributes

Modal.Header

PropTypeDefaultDescription
childrenReact.ReactNode-Header content
classNamestring-Additional classes
renderDOMRenderFunction<E, undefined>-Replaces the rendered <div>; E defaults to 'div'
...restHTMLAttributes-The attributes of the rendered element

Modal.Icon

PropTypeDefaultDescription
childrenReact.ReactNode-Icon content
classNamestring-Additional classes
renderDOMRenderFunction<E, undefined>-Replaces the rendered <div>; E defaults to 'div'
...restHTMLAttributes-The attributes of the rendered element

Modal.Heading

PropTypeDefaultDescription
childrenReact.ReactNode-Heading text; labels the dialog via aria-labelledby
classNamestring-Additional classes
...restHeadingProps-React Aria Heading attributes

Modal.Body

PropTypeDefaultDescription
childrenReact.ReactNode-Body content
classNamestring-Additional classes
renderDOMRenderFunction<E, undefined>-Replaces the rendered <div>; E defaults to 'div'
...restHTMLAttributes-The attributes of the rendered element

Modal.Footer

PropTypeDefaultDescription
childrenReact.ReactNode-Footer content, usually buttons
classNamestring-Additional classes
renderDOMRenderFunction<E, undefined>-Replaces the rendered <div>; E defaults to 'div'
...restHTMLAttributes-The attributes of the rendered element

Modal.CloseTrigger

PropTypeDefaultDescription
childrenReact.ReactNode-Custom close button content; defaults to the cross glyph
classNamestring | ((renderProps) => string)-Additional classes, or a function of the state
...restButtonProps-React Aria Button attributes; slot defaults to "close"

useOverlayState

import {useOverlayState} from "@peakui/react";

const state = useOverlayState({
  defaultOpen: false,
  onOpenChange: (isOpen) => console.log(isOpen),
});

state.isOpen; // current state
state.open(); // open the overlay
state.close(); // close the overlay
state.toggle(); // toggle the state
state.setOpen(true); // set the state directly

Render Props

PropTypeDescription
Modal.Backdrop className(renderProps: ModalOverlayRenderProps) => stringComputes classes from isEntering, isExiting and state
Modal.Container className(renderProps: ModalRenderProps) => stringComputes classes from isEntering, isExiting and state
Modal.Dialog children(opts: {close: () => void}) => React.ReactNodeRenders content with a callback that closes the modal

On this page