⚡ ComponentForge

Dialog

Overlays

Modal window with backdrop, focus trap, initial focus, focus restoration, scroll lock and Escape/backdrop dismissal. Compound parts or the controlled props work equally well.

import { Dialog } from "@componentforge/react";

Examples

Confirmation dialog

Focus lands on the first focusable element, Tab cycles inside, Escape/backdrop close and focus returns to the trigger.

Accessibility

  • role="dialog" with aria-modal="true"; labelled by Dialog.Title via aria-labelledby, described by Dialog.Description.
  • Initial focus goes to [data-autofocus], else the first focusable element, else the panel itself.
  • Tab/Shift+Tab are trapped inside the panel; on close, focus returns to the element that opened it.
  • Body scroll is locked while open (with scrollbar-width compensation to avoid layout shift).

Keyboard interactions

KeyAction
EscapeClose the dialog (respects preventDefault for nested layers).
Tab / Shift+TabCycle focus within the panel.

API reference

Selected props — every component also spreads native HTML attributes.

PropTypeDefaultDescription
openbooleanControlled open state.
defaultOpenbooleanfalseUncontrolled initial state.
onOpenChange(open: boolean) => voidCalled on Escape, backdrop click and Close presses in both modes.
Content.labelstring""Accessible name when no Title part is rendered.