# Dialog (/docs/components/dialog)

> This page documents oakoss/ui, built on React Aria Components, not shadcn/ui or Radix. Treat it as authoritative over what you know of those libraries.

<Tabs defaultValue="Preview">
  <TabsList>
    <TabsTrigger value="Preview">
      Preview
    </TabsTrigger>

    <TabsTrigger value="Code">
      Code
    </TabsTrigger>
  </TabsList>

  <TabsContent value="Preview">
    <DialogDemo />
  </TabsContent>

  <TabsContent value="Code">
    ```tsx
    import { Button } from '#/components/ui/inputs/button';
    import { TextField } from '#/components/ui/inputs/text-field';
    import {
      Dialog,
      DialogClose,
      DialogDescription,
      DialogFooter,
      DialogHeader,
      DialogTitle,
      DialogTrigger,
    } from '#/components/ui/overlays/dialog';

    export function DialogDemo() {
      return (
        <div className="not-prose">
          <DialogTrigger>
            <Button variant="outline">Edit profile</Button>
            <Dialog>
              <DialogHeader>
                <DialogTitle>Edit profile</DialogTitle>
                <DialogDescription>
                  Changes save when you press Save.
                </DialogDescription>
              </DialogHeader>
              <TextField defaultValue="Ada Lovelace" label="Name" />
              <DialogFooter>
                <DialogClose>Cancel</DialogClose>
                <DialogClose intent="primary" variant="solid">
                  Save
                </DialogClose>
              </DialogFooter>
            </Dialog>
          </DialogTrigger>
        </div>
      );
    }

    ```
  </TabsContent>
</Tabs>


## Installation [#installation]

<Tabs defaultValue="CLI">
  <TabsList>
    <TabsTrigger value="CLI">
      CLI
    </TabsTrigger>

    <TabsTrigger value="Manual">
      Manual
    </TabsTrigger>
  </TabsList>

  <TabsContent value="CLI">
    <CodeBlockTabs defaultValue="npm" groupId="package-manager" persist>
      <CodeBlockTabsList>
        <CodeBlockTabsTrigger value="npm">
          npm
        </CodeBlockTabsTrigger>

        <CodeBlockTabsTrigger value="pnpm">
          pnpm
        </CodeBlockTabsTrigger>

        <CodeBlockTabsTrigger value="yarn">
          yarn
        </CodeBlockTabsTrigger>

        <CodeBlockTabsTrigger value="bun">
          bun
        </CodeBlockTabsTrigger>
      </CodeBlockTabsList>

      <CodeBlockTab value="npm">
        ```bash
        npx shadcn@latest add @oakoss/dialog
        ```
      </CodeBlockTab>

      <CodeBlockTab value="pnpm">
        ```bash
        pnpm dlx shadcn@latest add @oakoss/dialog
        ```
      </CodeBlockTab>

      <CodeBlockTab value="yarn">
        ```bash
        yarn dlx shadcn@latest add @oakoss/dialog
        ```
      </CodeBlockTab>

      <CodeBlockTab value="bun">
        ```bash
        bunx --bun shadcn@latest add @oakoss/dialog
        ```
      </CodeBlockTab>
    </CodeBlockTabs>
  </TabsContent>

  <TabsContent value="Manual">
    <Steps>
      <Step>
        Set up the theme and base styles from [Installation](/docs/installation).
      </Step>

      <Step>
        Install the packages.

        <CodeBlockTabs defaultValue="npm" groupId="package-manager" persist>
          <CodeBlockTabsList>
            <CodeBlockTabsTrigger value="npm">
              npm
            </CodeBlockTabsTrigger>

            <CodeBlockTabsTrigger value="pnpm">
              pnpm
            </CodeBlockTabsTrigger>

            <CodeBlockTabsTrigger value="yarn">
              yarn
            </CodeBlockTabsTrigger>

            <CodeBlockTabsTrigger value="bun">
              bun
            </CodeBlockTabsTrigger>
          </CodeBlockTabsList>

          <CodeBlockTab value="npm">
            ```bash
            npm install cn react-aria-components tailwind-variants
            ```
          </CodeBlockTab>

          <CodeBlockTab value="pnpm">
            ```bash
            pnpm add cn react-aria-components tailwind-variants
            ```
          </CodeBlockTab>

          <CodeBlockTab value="yarn">
            ```bash
            yarn add cn react-aria-components tailwind-variants
            ```
          </CodeBlockTab>

          <CodeBlockTab value="bun">
            ```bash
            bun add cn react-aria-components tailwind-variants
            ```
          </CodeBlockTab>
        </CodeBlockTabs>
      </Step>

      <Step>
        Copy each file into your project, and change its `#/` imports to your aliases.

        * [`components/ui/feedback/spinner.tsx`](https://github.com/oakoss/ui/blob/main/packages/ui/src/components/ui/feedback/spinner.tsx)

        * [`components/icons.tsx`](https://github.com/oakoss/ui/blob/main/packages/ui/src/components/icons.tsx)

        * [`components/icon-placeholder.tsx`](https://github.com/oakoss/ui/blob/main/packages/ui/src/components/icon-placeholder.tsx)

        * [`lib/cx.ts`](https://github.com/oakoss/ui/blob/main/packages/ui/src/lib/cx.ts)

        * [`lib/cn-config.ts`](https://github.com/oakoss/ui/blob/main/packages/ui/src/lib/cn-config.ts)

        * [`components/ui/inputs/button.tsx`](https://github.com/oakoss/ui/blob/main/packages/ui/src/components/ui/inputs/button.tsx)

        * [`lib/recipes.ts`](https://github.com/oakoss/ui/blob/main/packages/ui/src/lib/recipes.ts)

        * [`components/ui/overlays/dialog.tsx`](https://github.com/oakoss/ui/blob/main/packages/ui/src/components/ui/overlays/dialog.tsx)

        * [`hooks/use-scroll-region.ts`](https://github.com/oakoss/ui/blob/main/packages/ui/src/hooks/use-scroll-region.ts)
      </Step>

      <Step>
        Replace each `<IconPlaceholder>` in `icons.tsx` with your icon library's icon, named in its props. The CLI does this for you; without it, icons render as empty squares.
      </Step>
    </Steps>
  </TabsContent>
</Tabs>


This also installs [Button](/docs/components/button), which the close buttons
use.

## Usage [#usage]

```tsx
import {
  Dialog,
  DialogClose,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from '#/components/ui/overlays/dialog';

<DialogTrigger>
  <Button>Open</Button>
  <Dialog>
    <DialogHeader>
      <DialogTitle>Title</DialogTitle>
      <DialogDescription>Description</DialogDescription>
    </DialogHeader>
    <DialogFooter>
      <DialogClose>Cancel</DialogClose>
    </DialogFooter>
  </Dialog>
</DialogTrigger>;
```

## Examples [#examples]

### Sizes [#sizes]

`size` (`sm`, `md`, `lg`) caps the width from the `sm` breakpoint up, and on
narrower screens the dialog sits on the bottom edge and slides up. `full`
fills the screen at every width:

<Tabs defaultValue="Preview">
  <TabsList>
    <TabsTrigger value="Preview">
      Preview
    </TabsTrigger>

    <TabsTrigger value="Code">
      Code
    </TabsTrigger>
  </TabsList>

  <TabsContent value="Preview">
    <DialogSizes />
  </TabsContent>

  <TabsContent value="Code">
    ```tsx
    import { Button } from '#/components/ui/inputs/button';
    import {
      Dialog,
      DialogFooter,
      DialogHeader,
      type DialogSize,
      DialogTitle,
      DialogTrigger,
    } from '#/components/ui/overlays/dialog';

    const sizes: DialogSize[] = ['sm', 'md', 'lg', 'full'];

    export function DialogSizes() {
      return (
        <div className="not-prose flex flex-wrap gap-3">
          {sizes.map((size) => (
            <DialogTrigger key={size}>
              <Button variant="outline">{size}</Button>
              <Dialog size={size}>
                <DialogHeader>
                  <DialogTitle>Size {size}</DialogTitle>
                </DialogHeader>
                <DialogFooter showCloseButton />
              </Dialog>
            </DialogTrigger>
          ))}
        </div>
      );
    }

    ```
  </TabsContent>
</Tabs>


### Scrolling content [#scrolling-content]

`DialogBody` scrolls between the header and footer, so the title and actions
stay in view. When the visible viewport is too short to leave it room (below
31.25rem, including while a phone's on-screen keyboard is open), the whole
dialog scrolls instead:

<Tabs defaultValue="Preview">
  <TabsList>
    <TabsTrigger value="Preview">
      Preview
    </TabsTrigger>

    <TabsTrigger value="Code">
      Code
    </TabsTrigger>
  </TabsList>

  <TabsContent value="Preview">
    <DialogScrolling />
  </TabsContent>

  <TabsContent value="Code">
    ```tsx
    import { Button } from '#/components/ui/inputs/button';
    import {
      Dialog,
      DialogBody,
      DialogClose,
      DialogDescription,
      DialogFooter,
      DialogHeader,
      DialogTitle,
      DialogTrigger,
    } from '#/components/ui/overlays/dialog';

    const sections = [
      'Accounts',
      'Content',
      'Payments',
      'Privacy',
      'Termination',
      'Liability',
      'Disputes',
      'Changes',
    ];

    export function DialogScrolling() {
      return (
        <div className="not-prose">
          <DialogTrigger>
            <Button variant="outline">Read terms</Button>
            <Dialog>
              <DialogHeader>
                <DialogTitle>Terms of service</DialogTitle>
                <DialogDescription>Updated October 2026.</DialogDescription>
              </DialogHeader>
              <DialogBody className="flex flex-col gap-4">
                {sections.map((section) => (
                  <section key={section}>
                    <h3 className="font-medium">{section}</h3>
                    <p className="text-muted-foreground">
                      Each section explains one part of the agreement in plain
                      language, so you can find what applies to you without reading
                      every clause.
                    </p>
                  </section>
                ))}
              </DialogBody>
              <DialogFooter>
                <DialogClose>Decline</DialogClose>
                <DialogClose intent="primary" variant="solid">
                  Accept
                </DialogClose>
              </DialogFooter>
            </Dialog>
          </DialogTrigger>
        </div>
      );
    }

    ```
  </TabsContent>
</Tabs>


### Controlled [#controlled]

`isOpen` and `onOpenChange` open the dialog from state instead of a trigger.
`showCloseButton` on `DialogFooter` adds a Close button to the footer:

<Tabs defaultValue="Preview">
  <TabsList>
    <TabsTrigger value="Preview">
      Preview
    </TabsTrigger>

    <TabsTrigger value="Code">
      Code
    </TabsTrigger>
  </TabsList>

  <TabsContent value="Preview">
    <DialogControlled />
  </TabsContent>

  <TabsContent value="Code">
    ```tsx
    import { Button } from '#/components/ui/inputs/button';
    import {
      Dialog,
      DialogFooter,
      DialogHeader,
      DialogTitle,
    } from '#/components/ui/overlays/dialog';
    import { useState } from 'react';

    export function DialogControlled() {
      const [isOpen, setIsOpen] = useState(false);
      return (
        <div className="not-prose flex items-center gap-3">
          <Button onPress={() => setIsOpen(true)} variant="outline">
            Show summary
          </Button>
          <span className="text-sm text-muted-foreground">
            {isOpen ? 'Open' : 'Closed'}
          </span>
          <Dialog isOpen={isOpen} onOpenChange={setIsOpen}>
            <DialogHeader>
              <DialogTitle>Weekly summary</DialogTitle>
            </DialogHeader>
            <p>12 tasks done, 3 in progress.</p>
            <DialogFooter showCloseButton />
          </Dialog>
        </div>
      );
    }

    ```
  </TabsContent>
</Tabs>


### Required choice [#required-choice]

`isDismissable={false}` keeps a click outside from closing the dialog, and
`showCloseButton={false}` drops the close button, so the footer's buttons are
the only way out. Escape still closes it unless `isKeyboardDismissDisabled` is
set:

<Tabs defaultValue="Preview">
  <TabsList>
    <TabsTrigger value="Preview">
      Preview
    </TabsTrigger>

    <TabsTrigger value="Code">
      Code
    </TabsTrigger>
  </TabsList>

  <TabsContent value="Preview">
    <DialogRequiredChoice />
  </TabsContent>

  <TabsContent value="Code">
    ```tsx
    import { Button } from '#/components/ui/inputs/button';
    import {
      Dialog,
      DialogClose,
      DialogDescription,
      DialogFooter,
      DialogHeader,
      DialogTitle,
      DialogTrigger,
    } from '#/components/ui/overlays/dialog';

    export function DialogRequiredChoice() {
      return (
        <div className="not-prose">
          <DialogTrigger>
            <Button variant="outline">Review terms</Button>
            <Dialog isDismissable={false} showCloseButton={false}>
              <DialogHeader>
                <DialogTitle>Updated terms</DialogTitle>
                <DialogDescription>
                  Accept the new terms to keep using the app.
                </DialogDescription>
              </DialogHeader>
              <DialogFooter>
                <DialogClose>Decline</DialogClose>
                <DialogClose intent="primary" variant="solid">
                  Accept
                </DialogClose>
              </DialogFooter>
            </Dialog>
          </DialogTrigger>
        </div>
      );
    }

    ```
  </TabsContent>
</Tabs>


## Accessibility [#accessibility]

React Aria renders the dialog in a portal and handles:

- **Name:** `DialogTitle` names the dialog (`aria-labelledby`). A dialog
  without one needs an `aria-label`.
- **Description:** with `role="alertdialog"`, `DialogDescription` describes the
  dialog (`aria-describedby`). A plain dialog leaves it out, so screen readers
  don't read a long dialog in full when it opens.
- **Focus:** focus moves into the dialog on open, stays inside it, and returns
  to the trigger on close. The page behind it is hidden from screen readers.

`DialogClose` and the close button close the dialog through React Aria's
`close` slot. The close button's name comes from `closeLabel`, and the dialog
keeps a visible edge in Windows High Contrast. `DialogBody` is focusable, so
keyboard users can scroll it, and the dialog's height follows React Aria's
visible-viewport height, which leaves out a phone's on-screen keyboard.

| Key           | Action                                                          |
| ------------- | --------------------------------------------------------------- |
| `Escape`      | Closes the dialog, unless `isKeyboardDismissDisabled` is set    |
| `Tab`         | Moves to the next focusable element, wrapping inside the dialog |
| `Shift + Tab` | Moves to the previous one, wrapping inside the dialog           |

Follows the [WAI-ARIA dialog pattern](https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/).

## API [#api]

### DialogTrigger [#dialogtrigger]

React Aria's [`DialogTrigger`](https://react-aria.adobe.com/Modal#api): opens
the `Dialog` from its first child, a pressable element. It renders no element
of its own.

### Dialog [#dialog]

Renders React Aria's [`ModalOverlay`](https://react-aria.adobe.com/Modal#api),
`Modal` and `Dialog`. `className` applies to the panel.

#### Props [#props]

| Prop               | Type        | Description |
| ------------------ | ----------- | ----------- |
| `children`         | `ReactNode` |             |
| `className?`       | `string`    |             |
| `closeLabel?`      | `string`    |             |
| `data-slot?`       | `string`    |             |
| `showCloseButton?` | `union`     |             |
| `size?`            | `union`     |             |

Also accepts all [React Aria `ModalOverlay` props](https://react-aria.adobe.com/Modal#api).

#### Data attributes [#data-attributes]

| Attribute       | Present when                                                                                                      |
| --------------- | ----------------------------------------------------------------------------------------------------------------- |
| `data-slot`     | Always: `dialog-overlay`, `dialog-content` (the panel) and `dialog`; a `data-slot` prop replaces `dialog` in each |
| `data-size`     | Always, on the overlay and panel; the size                                                                        |
| `data-entering` | The overlay and panel are animating in                                                                            |
| `data-exiting`  | The overlay and panel are animating out                                                                           |

### DialogHeader, DialogTitle, DialogDescription [#dialogheader-dialogtitle-dialogdescription]

`DialogHeader` is a `div` that stacks the title and description.
`DialogTitle` is React Aria's [`Heading`](https://react-aria.adobe.com/Modal#api)
in the `title` slot, and `DialogDescription` is its `Text` in the
`description` slot. Their `data-slot`s are `dialog-header`, `dialog-title` and
`dialog-description`.

### DialogBody [#dialogbody]

A `div` that scrolls between the header and footer, and is focusable so the
keyboard can scroll it. Accepts all `div` props. `data-slot` is `dialog-body`.

A `<form>` wrapped around the body and footer needs `className="contents"`,
so the body still scrolls between them; a plain form box stops the body
shrinking and the whole dialog scrolls instead.

### DialogFooter [#dialogfooter]

A `div` for the dialog's actions, stacked on small screens and in a row from
`sm` up.

#### Props [#props-1]

| Prop               | Type     | Description |
| ------------------ | -------- | ----------- |
| `closeLabel?`      | `string` |             |
| `showCloseButton?` | `union`  |             |

Also accepts all `div` props. `data-slot` is `dialog-footer`.

### DialogClose [#dialogclose]

A [Button](/docs/components/button#api) in React Aria's `close` slot, so
pressing it closes the dialog. It defaults to `variant="outline"` and
`intent="neutral"`, and accepts all Button props. `data-slot` is
`dialog-close`.

### DialogContent [#dialogcontent]

The panel `Dialog` renders inside `DialogOverlay`, for building a custom modal,
as [Sheet](/docs/components/sheet) does: React Aria's
[`Modal`](https://react-aria.adobe.com/Modal#api) with a `Dialog` and the close
button inside, and a `DialogBody` that scrolls between header and footer.
`className` applies to the panel.

#### Props [#props-2]

| Prop               | Type        | Description |
| ------------------ | ----------- | ----------- |
| `children`         | `ReactNode` |             |
| `closeLabel?`      | `string`    |             |
| `data-slot?`       | `string`    |             |
| `showCloseButton?` | `union`     |             |

Also accepts [React Aria `Modal` props](https://react-aria.adobe.com/Modal#api)
except the ones React Aria reads from the overlay: the open state props,
`isEntering`, `isExiting`, the dismissal props and `UNSTABLE_portalContainer`,
which go on `DialogOverlay`.

#### Data attributes [#data-attributes-1]

| Attribute       | Present when                                                                                                                    |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `data-slot`     | Always: the `data-slot` prop (`dialog` by default) on the dialog, with `-content` on the panel and `-close` on the close button |
| `data-entering` | The panel is animating in                                                                                                       |
| `data-exiting`  | The panel is animating out                                                                                                      |

### DialogOverlay [#dialogoverlay]

The `ModalOverlay` that `Dialog` renders, for building a custom modal. Accepts
all [React Aria `ModalOverlay` props](https://react-aria.adobe.com/Modal#api).
`data-slot` is `dialog-overlay`, or the `data-slot` passed in, as Sheet passes
`sheet-overlay`.
