Modal
A focus-trapping dialog for confirmations and short tasks.
Use a modal to confirm an action that is hard to undo, or for a short task that should block the page until it's done, such as inviting a member. Longer tasks belong on their own page.
Installation
Pro components install from the Aloxe registry with the shadcn CLI. Once per project, add the registry to components.json and put a registry token in the ALOXE_TOKEN environment variable. Registry has the details.
{
"registries": {
"@aloxe": {
"url": "https://<aloxe-site>/r/{name}.json",
"headers": { "Authorization": "Bearer ${ALOXE_TOKEN}" }
}
}
}Then add the component:
npx shadcn@latest add @aloxe/modalThe CLI copies the source into components/ui/aloxe/, so it never overwrites your own ui components. It also installs @aloxe/react, @aloxe/tokens and @base-ui/react.
Import the tokens once in your global stylesheet, after Tailwind, and add an @source for the copied files and one for @aloxe/react, so Tailwind generates their classes. @source paths are relative to the stylesheet; these assume src/app/globals.css and src/components/ui/aloxe/.
@import "tailwindcss";
@import "@aloxe/tokens/aloxe.css";
@import "@aloxe/tokens/tailwind.css";
@source "../components/ui/aloxe";
@source "../../node_modules/@aloxe/react/dist";Installation covers the theme and brand attributes.
Usage
import { Button } from "@aloxe/react";
import { Modal, ModalClose } from "@/components/ui/aloxe/modal";
<Modal
trigger={<Button variant="danger">Delete project</Button>}
title="Delete Northwind website?"
description="It is deleted for everyone. You can't undo this."
footer={
<>
<ModalClose render={<Button variant="secondary" />}>Cancel</ModalClose>
<Button variant="danger" onClick={deleteProject}>Delete project</Button>
</>
}
/>title is required: it names the dialog. Put the actions in footer, primary last. ModalClose closes the modal; give it the look of a button with render.
The modal opens in a layer attached to the page body. It copies the data-theme and data-brand of the place <Modal> is rendered in.
Examples
Sizes
size="sm" (400 px, the default) fits a confirmation. size="md" (560 px) fits a short form or a summary. Under 640 px both keep 16 px from the screen edges and the footer actions stack full width.
Controlled, with a form
Control open with onOpenChange to close the modal after a submit. The submit button sits in the footer and points at the form with its form attribute, so Enter in a field submits too.
Accessibility
| Key | Action |
|---|---|
| Enter or Space | Opens the modal when the trigger has focus. Focus moves to the first focusable element inside. |
| Tab and Shift+Tab | Move between the modal's controls. Focus stays inside the modal. |
| Escape | Closes the modal. Focus returns to the element that opened it. |
- Follows the WAI-ARIA dialog pattern:
role="dialog"witharia-modal, named by the title and described by the description. - The page behind is inert and doesn't scroll while the modal is open. A click on the backdrop closes it unless
disablePointerDismissalis set. - Use
initialFocusto start on a safer control, such as Cancel in a destructive confirmation. - The open and close fade is 180 ms and is turned off with
prefers-reduced-motion.
API reference
Every part accepts className and renders a data-aloxe attribute you can target in CSS, such as [data-aloxe="modal"].
Modal
Extends Base UI Dialog.Popup.
| Prop | Type | Default | Description |
|---|---|---|---|
| title (required) | ReactNode | The heading. It names the dialog (aria-labelledby). | |
| description | ReactNode | Supporting text under the title, linked with aria-describedby. | |
| children | ReactNode | The body, such as a form or a summary. | |
| footer | ReactNode | The actions, right-aligned with an 8 px gap and stacked full width under 640 px. Put the primary action last. | |
| size | "sm" | "md" | "sm" | 400 or 560 px wide. On small screens the modal keeps 16 px from each edge. |
| trigger | ReactElement | An element that opens the modal, such as a Button. Optional when you control open. | |
| open | boolean | Controlled open state. Pair with onOpenChange. | |
| defaultOpen | boolean | false | Initial open state when uncontrolled. |
| onOpenChange | (open: boolean, details) => void | Called when the modal opens or closes, including on Escape and backdrop clicks. | |
| disablePointerDismissal | boolean | false | Keeps the modal open on a backdrop click. Escape still closes it. |
| initialFocus | boolean | RefObject<HTMLElement> | ((type) => HTMLElement | boolean | null) | The element that gets focus on open. Defaults to the first focusable element. | |
| finalFocus | boolean | RefObject<HTMLElement> | ((type) => HTMLElement | boolean | null) | The element that gets focus on close. Defaults to the element that opened the modal. | |
| className | string | Classes for the modal panel. |
ModalClose
Extends Base UI Dialog.Close.
| Prop | Type | Default | Description |
|---|---|---|---|
| render | ReactElement | Gives it the look of a button, such as render={<Button variant="secondary" />}. Unstyled otherwise. | |
| children | ReactNode | The button label. | |
| className | string | Classes for the close button. |
Figma
Matches the Modal component in the Pro Figma file. Figma Size (Sm, Md) maps to size; Title, Description and Body map to title, description and children; Show footer maps to passing footer.
See Figma for where to get the file and how its names map to code.
Pro
Modal is part of Aloxe Pro. The previews on this page are open to everyone; the Code tab shows the example source once you sign in with a Pro license. See Access and licenses and Pricing.