Skip to content

Router that virtually distributes inference across connected devices in the home.

Go
329 KB
Raw Blame

Modal

A modal dialog that can be triggered by a button or other element. Uses the native <dialog> element for progressive enhancement, providing built-in backdrop styling, focus management, and support for form method="dialog" for native close behavior.

Examples

Basic Modal

Use when you need to interrupt the user for a confirmation or brief task that requires focused attention.

<Modal
    slotTrigger={<Button>Open Modal</Button>}
    slotHeading="Confirm Action"
    slotFooter={
        <>
            <ModalCloseButton kind="tertiary">Cancel</ModalCloseButton>
            <Button color="brand">Confirm</Button>
        </>
    }
>
    Are you sure you want to proceed with this action?
</Modal>

Fullscreen Modal

Use when the modal content needs maximum screen real estate, such as previews or complex editors.

<Modal
    className="size-full"
    slotTrigger={<Button>Open Fullscreen</Button>}
    slotHeading="Fullscreen Modal"
    slotFooter={
        <>
            <ModalCloseButton kind="tertiary">Close</ModalCloseButton>
            <Button color="brand">Save</Button>
        </>
    }
>
    Content that benefits from maximum screen space.
</Modal>

Non Dismissible Modal

Use when the user must complete an action before continuing, preventing dismissal via escape or backdrop click.

<Modal
    dismissible={false}
    slotTrigger={<Button>Open Required Modal</Button>}
    slotHeading="Required Action"
    slotFooter={<Button color="brand">Acknowledge</Button>}
>
    You must complete this action before continuing.
</Modal>

Multi Step Modal

Use for wizards or forms where accidental backdrop dismissal would lose user progress. Disables closeOnClickOutside and uses ml-auto on the cancel button to push it away from a left-aligned back button.

<Modal
    closeOnClickOutside={false}
    slotTrigger={<Button>Configure Deployment</Button>}
    slotHeading="Step 2 of 3 — Resources"
    slotFooter={
        <>
            <Button kind="secondary">Back</Button>
            <ModalCloseButton className="ml-auto" kind="tertiary">
                Cancel
            </ModalCloseButton>
            <Button color="brand">Next</Button>
        </>
    }
>
    Choose the resources for this deployment. Your progress is preserved across steps.
</Modal>

Form Modal

Use when the modal contains a form that should wrap the content for native form submission.

<Modal
    slotTrigger={<Button>Open Form</Button>}
    slotHeading="Submit Feedback"
    renderContent={({ children }) => <form onSubmit={handleSubmit}>{children}</form>}
    slotFooter={
        <>
            <ModalCloseButton kind="tertiary">Cancel</ModalCloseButton>
            <Button type="submit" color="brand">
                Submit
            </Button>
        </>
    }
>
    Form content goes here
</Modal>

Native Form Modal

Use for server-rendered actions that must work without JavaScript. The body is wrapped in a real <form action> while formMethod="dialog" on the cancel and X close buttons closes the modal without submitting.

<Modal
    slotTrigger={<Button color="danger">Delete Item</Button>}
    slotHeading="Confirm Deletion"
    attributes={{
        ModalCloseButton: {
            type: 'submit',
            formMethod: 'dialog',
            formNoValidate: true
        }
    }}
    renderContent={({ children }) => (
        <form action="/api/delete-item" method="post">
            {children}
        </form>
    )}
    slotFooter={
        <>
            <input type="hidden" name="itemId" value="123" />
            <Button type="submit" formMethod="dialog" formNoValidate kind="tertiary">
                Cancel
            </Button>
            <Button type="submit" color="danger">
                Delete
            </Button>
        </>
    }
>
    Are you sure you want to delete this item? This action cannot be undone.
</Modal>

Anchor Trigger Modal

Use slotAnchorTrigger paired with id for progressive enhancement: JavaScript opens the modal in place, while users without JavaScript navigate to the anchor's href as a fallback page.

<Modal
    id="modal-anchor-trigger-example"
    slotAnchorTrigger={<Anchor href="/settings">Open Settings</Anchor>}
    slotHeading="Settings"
    slotFooter={
        <>
            <ModalCloseButton kind="tertiary">Cancel</ModalCloseButton>
            <Button color="brand">Save</Button>
        </>
    }
>
    Adjust your preferences below.
</Modal>

Composed

Use composed primitives when you need full control over the modal layout and behavior.

<ModalRoot>
    <ModalTrigger asChild>
        <Button>Open Modal</Button>
    </ModalTrigger>
    <ModalContent>
        <ModalHeading>Composed Heading</ModalHeading>
        <ModalMain>Composed modal content using primitives directly.</ModalMain>
        <ModalFooter>
            <ModalCloseButton kind="tertiary">Cancel</ModalCloseButton>
            <Button color="brand">Save</Button>
        </ModalFooter>
    </ModalContent>
</ModalRoot>

Props

Prop Type Default Description
asChild boolean - When true, treats the immediate child as the host element, merging this component's props with the child's props. The child's children will be slotted into the component's defined content placement.
closeButtonProps { form?: string; slot?: string; style?: React.CSSProperties; title?: string; defaultValue?: string | number | readonly string[]; ref?: React.Ref<HTMLButtonElement>; key?: React.Key; defaultChecked?: boolean; suppressContentEditableWarning?: boolean; suppressHydrationWarning?: boolean; accessKey?: string; autoCapitalize?: "off" | "none" | "on" | "sentences" | "words" | "characters" | (string & {}); autoFocus?: boolean; contentEditable?: Booleanish | "inherit" | "plaintext-only"; contextMenu?: string; dir?: string; draggable?: Booleanish; enterKeyHint?: "search" | "enter" | "done" | "go" | "next" | "previous" | "send"; hidden?: boolean; id?: string; lang?: string; nonce?: string; spellCheck?: Booleanish; tabIndex?: number; translate?: "yes" | "no"; radioGroup?: string; role?: React.AriaRole; about?: string; content?: string; datatype?: string; inlist?: any; prefix?: string; property?: string; rel?: string; resource?: string; rev?: string; typeof?: string; vocab?: string; autoCorrect?: string; autoSave?: string; color?: "brand" | "neutral" | "danger"; itemProp?: string; itemScope?: boolean; itemType?: string; itemID?: string; itemRef?: string; results?: number; security?: string; unselectable?: "off" | "on"; popover?: "" | "auto" | "manual"; popoverTargetAction?: "toggle" | "show" | "hide"; popoverTarget?: string; inert?: boolean; inputMode?: "search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal"; is?: string; exportparts?: string; part?: string; "aria-activedescendant"?: string; "aria-atomic"?: Booleanish; "aria-autocomplete"?: "none" | "list" | "inline" | "both"; "aria-braillelabel"?: string; "aria-brailleroledescription"?: string; "aria-busy"?: Booleanish; "aria-checked"?: boolean | "true" | "false" | "mixed"; "aria-colcount"?: number; "aria-colindex"?: number; "aria-colindextext"?: string; "aria-colspan"?: number; "aria-controls"?: string; "aria-current"?: boolean | "time" | "true" | "false" | "page" | "step" | "location" | "date"; "aria-describedby"?: string; "aria-description"?: string; "aria-details"?: string; "aria-disabled"?: Booleanish; "aria-dropeffect"?: "link" | "none" | "copy" | "execute" | "move" | "popup"; "aria-errormessage"?: string; "aria-expanded"?: Booleanish; "aria-flowto"?: string; "aria-grabbed"?: Booleanish; "aria-haspopup"?: boolean | "dialog" | "menu" | "true" | "false" | "grid" | "listbox" | "tree"; "aria-hidden"?: Booleanish; "aria-invalid"?: boolean | "true" | "false" | "grammar" | "spelling"; "aria-keyshortcuts"?: string; "aria-label"?: string; "aria-labelledby"?: string; "aria-level"?: number; "aria-live"?: "off" | "assertive" | "polite"; "aria-modal"?: Booleanish; "aria-multiline"?: Booleanish; "aria-multiselectable"?: Booleanish; "aria-orientation"?: "horizontal" | "vertical"; "aria-owns"?: string; "aria-placeholder"?: string; "aria-posinset"?: number; "aria-pressed"?: boolean | "true" | "false" | "mixed"; "aria-readonly"?: Booleanish; "aria-relevant"?: "text" | "additions" | "additions removals" | "additions text" | "all" | "removals" | "removals additions" | "removals text" | "text additions" | "text removals"; "aria-required"?: Booleanish; "aria-roledescription"?: string; "aria-rowcount"?: number; "aria-rowindex"?: number; "aria-rowindextext"?: string; "aria-rowspan"?: number; "aria-selected"?: Booleanish; "aria-setsize"?: number; "aria-sort"?: "none" | "ascending" | "descending" | "other"; "aria-valuemax"?: number; "aria-valuemin"?: number; "aria-valuenow"?: number; "aria-valuetext"?: string; dangerouslySetInnerHTML?: { __html: string | TrustedHTML; }; onCopy?: React.ClipboardEventHandler<HTMLButtonElement>; onCopyCapture?: React.ClipboardEventHandler<HTMLButtonElement>; onCut?: React.ClipboardEventHandler<HTMLButtonElement>; onCutCapture?: React.ClipboardEventHandler<HTMLButtonElement>; onPaste?: React.ClipboardEventHandler<HTMLButtonElement>; onPasteCapture?: React.ClipboardEventHandler<HTMLButtonElement>; onCompositionEnd?: React.CompositionEventHandler<HTMLButtonElement>; onCompositionEndCapture?: React.CompositionEventHandler<HTMLButtonElement>; onCompositionStart?: React.CompositionEventHandler<HTMLButtonElement>; onCompositionStartCapture?: React.CompositionEventHandler<HTMLButtonElement>; onCompositionUpdate?: React.CompositionEventHandler<HTMLButtonElement>; onCompositionUpdateCapture?: React.CompositionEventHandler<HTMLButtonElement>; onFocus?: React.FocusEventHandler<HTMLButtonElement>; onFocusCapture?: React.FocusEventHandler<HTMLButtonElement>; onBlur?: React.FocusEventHandler<HTMLButtonElement>; onBlurCapture?: React.FocusEventHandler<HTMLButtonElement>; onChange?: React.FormEventHandler<HTMLButtonElement>; onChangeCapture?: React.FormEventHandler<HTMLButtonElement>; onBeforeInput?: React.InputEventHandler<HTMLButtonElement>; onBeforeInputCapture?: React.FormEventHandler<HTMLButtonElement>; onInput?: React.FormEventHandler<HTMLButtonElement>; onInputCapture?: React.FormEventHandler<HTMLButtonElement>; onReset?: React.FormEventHandler<HTMLButtonElement>; onResetCapture?: React.FormEventHandler<HTMLButtonElement>; onSubmit?: React.FormEventHandler<HTMLButtonElement>; onSubmitCapture?: React.FormEventHandler<HTMLButtonElement>; onInvalid?: React.FormEventHandler<HTMLButtonElement>; onInvalidCapture?: React.FormEventHandler<HTMLButtonElement>; onLoad?: React.ReactEventHandler<HTMLButtonElement>; onLoadCapture?: React.ReactEventHandler<HTMLButtonElement>; onError?: React.ReactEventHandler<HTMLButtonElement>; onErrorCapture?: React.ReactEventHandler<HTMLButtonElement>; onKeyDown?: React.KeyboardEventHandler<HTMLButtonElement>; onKeyDownCapture?: React.KeyboardEventHandler<HTMLButtonElement>; onKeyPress?: React.KeyboardEventHandler<HTMLButtonElement>; onKeyPressCapture?: React.KeyboardEventHandler<HTMLButtonElement>; onKeyUp?: React.KeyboardEventHandler<HTMLButtonElement>; onKeyUpCapture?: React.KeyboardEventHandler<HTMLButtonElement>; onAbort?: React.ReactEventHandler<HTMLButtonElement>; onAbortCapture?: React.ReactEventHandler<HTMLButtonElement>; onCanPlay?: React.ReactEventHandler<HTMLButtonElement>; onCanPlayCapture?: React.ReactEventHandler<HTMLButtonElement>; onCanPlayThrough?: React.ReactEventHandler<HTMLButtonElement>; onCanPlayThroughCapture?: React.ReactEventHandler<HTMLButtonElement>; onDurationChange?: React.ReactEventHandler<HTMLButtonElement>; onDurationChangeCapture?: React.ReactEventHandler<HTMLButtonElement>; onEmptied?: React.ReactEventHandler<HTMLButtonElement>; onEmptiedCapture?: React.ReactEventHandler<HTMLButtonElement>; onEncrypted?: React.ReactEventHandler<HTMLButtonElement>; onEncryptedCapture?: React.ReactEventHandler<HTMLButtonElement>; onEnded?: React.ReactEventHandler<HTMLButtonElement>; onEndedCapture?: React.ReactEventHandler<HTMLButtonElement>; onLoadedData?: React.ReactEventHandler<HTMLButtonElement>; onLoadedDataCapture?: React.ReactEventHandler<HTMLButtonElement>; onLoadedMetadata?: React.ReactEventHandler<HTMLButtonElement>; onLoadedMetadataCapture?: React.ReactEventHandler<HTMLButtonElement>; onLoadStart?: React.ReactEventHandler<HTMLButtonElement>; onLoadStartCapture?: React.ReactEventHandler<HTMLButtonElement>; onPause?: React.ReactEventHandler<HTMLButtonElement>; onPauseCapture?: React.ReactEventHandler<HTMLButtonElement>; onPlay?: React.ReactEventHandler<HTMLButtonElement>; onPlayCapture?: React.ReactEventHandler<HTMLButtonElement>; onPlaying?: React.ReactEventHandler<HTMLButtonElement>; onPlayingCapture?: React.ReactEventHandler<HTMLButtonElement>; onProgress?: React.ReactEventHandler<HTMLButtonElement>; onProgressCapture?: React.ReactEventHandler<HTMLButtonElement>; onRateChange?: React.ReactEventHandler<HTMLButtonElement>; onRateChangeCapture?: React.ReactEventHandler<HTMLButtonElement>; onSeeked?: React.ReactEventHandler<HTMLButtonElement>; onSeekedCapture?: React.ReactEventHandler<HTMLButtonElement>; onSeeking?: React.ReactEventHandler<HTMLButtonElement>; onSeekingCapture?: React.ReactEventHandler<HTMLButtonElement>; onStalled?: React.ReactEventHandler<HTMLButtonElement>; onStalledCapture?: React.ReactEventHandler<HTMLButtonElement>; onSuspend?: React.ReactEventHandler<HTMLButtonElement>; onSuspendCapture?: React.ReactEventHandler<HTMLButtonElement>; onTimeUpdate?: React.ReactEventHandler<HTMLButtonElement>; onTimeUpdateCapture?: React.ReactEventHandler<HTMLButtonElement>; onVolumeChange?: React.ReactEventHandler<HTMLButtonElement>; onVolumeChangeCapture?: React.ReactEventHandler<HTMLButtonElement>; onWaiting?: React.ReactEventHandler<HTMLButtonElement>; onWaitingCapture?: React.ReactEventHandler<HTMLButtonElement>; onAuxClick?: React.MouseEventHandler<HTMLButtonElement>; onAuxClickCapture?: React.MouseEventHandler<HTMLButtonElement>; onClick?: React.MouseEventHandler<HTMLButtonElement>; onClickCapture?: React.MouseEventHandler<HTMLButtonElement>; onContextMenu?: React.MouseEventHandler<HTMLButtonElement>; onContextMenuCapture?: React.MouseEventHandler<HTMLButtonElement>; onDoubleClick?: React.MouseEventHandler<HTMLButtonElement>; onDoubleClickCapture?: React.MouseEventHandler<HTMLButtonElement>; onDrag?: React.DragEventHandler<HTMLButtonElement>; onDragCapture?: React.DragEventHandler<HTMLButtonElement>; onDragEnd?: React.DragEventHandler<HTMLButtonElement>; onDragEndCapture?: React.DragEventHandler<HTMLButtonElement>; onDragEnter?: React.DragEventHandler<HTMLButtonElement>; onDragEnterCapture?: React.DragEventHandler<HTMLButtonElement>; onDragExit?: React.DragEventHandler<HTMLButtonElement>; onDragExitCapture?: React.DragEventHandler<HTMLButtonElement>; onDragLeave?: React.DragEventHandler<HTMLButtonElement>; onDragLeaveCapture?: React.DragEventHandler<HTMLButtonElement>; onDragOver?: React.DragEventHandler<HTMLButtonElement>; onDragOverCapture?: React.DragEventHandler<HTMLButtonElement>; onDragStart?: React.DragEventHandler<HTMLButtonElement>; onDragStartCapture?: React.DragEventHandler<HTMLButtonElement>; onDrop?: React.DragEventHandler<HTMLButtonElement>; onDropCapture?: React.DragEventHandler<HTMLButtonElement>; onMouseDown?: React.MouseEventHandler<HTMLButtonElement>; onMouseDownCapture?: React.MouseEventHandler<HTMLButtonElement>; onMouseEnter?: React.MouseEventHandler<HTMLButtonElement>; onMouseLeave?: React.MouseEventHandler<HTMLButtonElement>; onMouseMove?: React.MouseEventHandler<HTMLButtonElement>; onMouseMoveCapture?: React.MouseEventHandler<HTMLButtonElement>; onMouseOut?: React.MouseEventHandler<HTMLButtonElement>; onMouseOutCapture?: React.MouseEventHandler<HTMLButtonElement>; onMouseOver?: React.MouseEventHandler<HTMLButtonElement>; onMouseOverCapture?: React.MouseEventHandler<HTMLButtonElement>; onMouseUp?: React.MouseEventHandler<HTMLButtonElement>; onMouseUpCapture?: React.MouseEventHandler<HTMLButtonElement>; onSelect?: React.ReactEventHandler<HTMLButtonElement>; onSelectCapture?: React.ReactEventHandler<HTMLButtonElement>; onTouchCancel?: React.TouchEventHandler<HTMLButtonElement>; onTouchCancelCapture?: React.TouchEventHandler<HTMLButtonElement>; onTouchEnd?: React.TouchEventHandler<HTMLButtonElement>; onTouchEndCapture?: React.TouchEventHandler<HTMLButtonElement>; onTouchMove?: React.TouchEventHandler<HTMLButtonElement>; onTouchMoveCapture?: React.TouchEventHandler<HTMLButtonElement>; onTouchStart?: React.TouchEventHandler<HTMLButtonElement>; onTouchStartCapture?: React.TouchEventHandler<HTMLButtonElement>; onPointerDown?: React.PointerEventHandler<HTMLButtonElement>; onPointerDownCapture?: React.PointerEventHandler<HTMLButtonElement>; onPointerMove?: React.PointerEventHandler<HTMLButtonElement>; onPointerMoveCapture?: React.PointerEventHandler<HTMLButtonElement>; onPointerUp?: React.PointerEventHandler<HTMLButtonElement>; onPointerUpCapture?: React.PointerEventHandler<HTMLButtonElement>; onPointerCancel?: React.PointerEventHandler<HTMLButtonElement>; onPointerCancelCapture?: React.PointerEventHandler<HTMLButtonElement>; onPointerEnter?: React.PointerEventHandler<HTMLButtonElement>; onPointerLeave?: React.PointerEventHandler<HTMLButtonElement>; onPointerOver?: React.PointerEventHandler<HTMLButtonElement>; onPointerOverCapture?: React.PointerEventHandler<HTMLButtonElement>; onPointerOut?: React.PointerEventHandler<HTMLButtonElement>; onPointerOutCapture?: React.PointerEventHandler<HTMLButtonElement>; onGotPointerCapture?: React.PointerEventHandler<HTMLButtonElement>; onGotPointerCaptureCapture?: React.PointerEventHandler<HTMLButtonElement>; onLostPointerCapture?: React.PointerEventHandler<HTMLButtonElement>; onLostPointerCaptureCapture?: React.PointerEventHandler<HTMLButtonElement>; onScroll?: React.UIEventHandler<HTMLButtonElement>; onScrollCapture?: React.UIEventHandler<HTMLButtonElement>; onScrollEnd?: React.UIEventHandler<HTMLButtonElement>; onScrollEndCapture?: React.UIEventHandler<HTMLButtonElement>; onWheel?: React.WheelEventHandler<HTMLButtonElement>; onWheelCapture?: React.WheelEventHandler<HTMLButtonElement>; onAnimationStart?: React.AnimationEventHandler<HTMLButtonElement>; onAnimationStartCapture?: React.AnimationEventHandler<HTMLButtonElement>; onAnimationEnd?: React.AnimationEventHandler<HTMLButtonElement>; onAnimationEndCapture?: React.AnimationEventHandler<HTMLButtonElement>; onAnimationIteration?: React.AnimationEventHandler<HTMLButtonElement>; onAnimationIterationCapture?: React.AnimationEventHandler<HTMLButtonElement>; onToggle?: React.ToggleEventHandler<HTMLButtonElement>; onBeforeToggle?: React.ToggleEventHandler<HTMLButtonElement>; onTransitionCancel?: React.TransitionEventHandler<HTMLButtonElement>; onTransitionCancelCapture?: React.TransitionEventHandler<HTMLButtonElement>; onTransitionEnd?: React.TransitionEventHandler<HTMLButtonElement>; onTransitionEndCapture?: React.TransitionEventHandler<HTMLButtonElement>; onTransitionRun?: React.TransitionEventHandler<HTMLButtonElement>; onTransitionRunCapture?: React.TransitionEventHandler<HTMLButtonElement>; onTransitionStart?: React.TransitionEventHandler<HTMLButtonElement>; onTransitionStartCapture?: React.TransitionEventHandler<HTMLButtonElement>; asChild?: boolean; disabled?: boolean; name?: string; value?: string | number | readonly string[]; formAction?: string | ((formData: FormData) => void | Promise<void>); formEncType?: string; formMethod?: string; formNoValidate?: boolean; formTarget?: string; type?: "button" | "submit" | "reset"; size?: "small" | "tiny" | "medium" | "large"; } - Props to pass to the close button. This can be used to customize the close button's behavior for progressive enhancement scenarios.
closeOnClickOutside boolean -
defaultOpen boolean false Initial open state when the dialog is uncontrolled.
density "compact" | "standard" | "spacious" "standard" The "density" of the component. This affects the padding/spacing of the component and its children. By default, the component will inherit density from its parent, which is usually standard. - Setting to null or undefined will allow the component to inherit density from its parent. - Setting to compact will reduce the padding/spacing of the component and its children. - Setting to standard will use the standard padding/spacing of the component and its children. - Setting to spacious will increase the padding/spacing of the component and its children.
dismissible boolean true Controls whether the modal is dismissible. Use this to disable the built in closing mechanisms. When set to false this will: - Hide the close button - Disable the escape key closing the modal - Disable clicking outside the modal from closing it
forceMount boolean -
hideCloseButton boolean - When true, hides the modal's close button. Useful for modals that should not be dismissible.
modal boolean true When true, the dialog is opened via HTMLDialogElement.showModal(), rendering a top-layer backdrop and trapping focus. When false, the dialog is opened via HTMLDialogElement.show() as a non-modal dialog.
onEscapeKeyDown (event: KeyboardEvent) => void -
onInteractOutside (event: MouseEvent) => void - Event handler called when an interaction event occurs outside the bounds of the component. It can be prevented by calling event.preventDefault.
onOpenAutoFocus (event: Event) => void -
onOpenChange (open: boolean) => void - Callback invoked whenever the dialog's open state changes, in both controlled and uncontrolled modes. Consecutive transitions to the same value are deduped, so the callback fires at most once per state change.
onPointerDownOutside (event: MouseEvent) => void - Event handler called when a pointer event occurs outside the bounds of the component. It can be prevented by calling event.preventDefault.
open boolean - Controlled open state. When provided, the hook operates in controlled mode and defaultOpen is ignored. The consumer is responsible for updating this value in response to {@link UseDialogOptions.onOpenChange} callbacks.
renderContent (props: { children: React.ReactNode; }) => React.ReactElement<unknown, string | React.JSXElementConstructor<any>> - A render function that wraps the modal content. This is useful for injecting elements like forms. When provided, this will force asChild on the ModalContent component.
slotAnchorTrigger ReactNode - The content to render in the modal anchor trigger. This provides progressive enhancement by using an anchor that opens the modal when JavaScript is enabled and navigates to a fallback URL when it is disabled.
slotFooter ReactNode - The content to render in the modal footer. Handles spacing its children for you, and by default aligns the children to the right.
slotHeading ReactNode - The content to render in the modal heading. If not provided, the modal will render empty space to make room for the close button.
slotTrigger ReactNode - The content to render in the modal trigger. This trigger will open the modal when clicked.