> For AI agents: the complete documentation index is available at https://wallarm.github.io/design-system/llms.txt, the full documentation bundle is available at https://wallarm.github.io/design-system/llms-full.txt.

# Confirmation dialogs

**Components:** [`Dialog`](https://wallarm.github.io/design-system/components/dialog.md), [`Drawer`](https://wallarm.github.io/design-system/components/drawer.md), [`Button`](https://wallarm.github.io/design-system/components/button.md), [`Input`](https://wallarm.github.io/design-system/components/input.md), [`Toast`](https://wallarm.github.io/design-system/components/toast.md), [`Toaster`](https://wallarm.github.io/design-system/components/toast.md)

A confirmation dialog asks one question about one action, then runs that action or cancels it. Compose it from `Dialog` parts. There is no `ConfirmDialog`, `AlertDialog`, `useConfirm` or `UnsavedChangesDialog`.

## When to use

| Need                                   | Use                                                                                            | Not                                                           |
| -------------------------------------- | ---------------------------------------------------------------------------------------------- | ------------------------------------------------------------- |
| Delete, revoke, deactivate, disable    | `Dialog width={400}`, confirm `color='destructive'`                                            | A toast with Undo, or a `Switch` that silently removes access |
| Activate or enable                     | `Dialog width={400}`, default brand confirm                                                    | `color='destructive'`                                         |
| Delete that also breaks linked objects | Type-to-confirm: no `width` (560) + `Input`                                                    | A longer description                                          |
| Closing a drawer with unsaved edits    | Unsaved-changes guard, no `width` (560)                                                        | `window.confirm` or `closeOnEscape={false}`                   |
| Continue despite a warning             | `Dialog width={400}`, brand "Create anyway"                                                    | An `Alert` to dismiss first                                   |
| Reversible action that loses no data   | No dialog; run it and show a toast                                                             | A confirmation                                                |
| Several fields before acting           | [Create and edit forms](https://wallarm.github.io/design-system/patterns/create-edit-forms.md) | A form inside `DialogBody`                                    |
| Report the result                      | A toast                                                                                        | A second dialog that says "Done"                              |

## Rules

### Structure

- Import every `Dialog*` part from `@wallarm-org/design-system/Dialog`. `Dialog` is not exported from the package root.
- Use `width={400}` for delete, state change and proceed-anyway. Omit `width` (560) for type-to-confirm and unsaved changes. **Never** use `960` for a confirmation.
- Write the width as a number; `DIALOG_SIZES` and a `size` prop do not exist. If the description wraps, keep 400.
- Footer order, left to right: Cancel, then confirm. The confirm button is always rightmost.
- Confirm buttons use the default `variant='primary'`. Every other footer button is `variant='ghost' color='neutral'`.
- **Never** use `color='destructive'` for an action that grants access or creates something.
- Wrap Cancel in `DialogClose asChild`. **Never** wrap the confirm button in `DialogClose`: it closes the dialog before the request runs.
- **Never** add a close button to `DialogHeader`. It renders the close X itself.
- There is no `onConfirm`, `onCancel`, `confirmLabel`, `destructive` or `loading` prop on `Dialog`, no `DialogAction`/`DialogCancel`, and no initial-focus prop.

### Spacing

- The parts own all padding (header `pt-20 pb-16 px-24`, body `px-24 py-8`, footer `px-24 py-16 gap-8`). Keep the body's 8px though Figma draws the input flush.
- **Never** add `p-*`, `gap-*` or `space-y-*` around dialog content, wrap footer buttons in a `div`/`HStack`, or pass `size` to them (default 36px).
- **Never** pass `className` to `DialogHeader`, `DialogBody` or `DialogFooter`. They take only `children` and `ref`.

### Behavior

- While the request runs, pass `loading={pending}` to confirm (it also disables it; do not add `disabled={pending}`) and ignore close requests. Close only on success; on failure keep it open with an error toast.
- If the dialog closes, reset the type-to-confirm input to `''`. Match the entity name exactly, case-sensitive.
- If the dialog opens from a `Drawer`, render it inside `DrawerContent`. See [Layering](https://wallarm.github.io/design-system/foundations/layering.md).
- To guard unsaved changes, intercept `onOpenChange(false)` on the `Drawer`. One handler covers the close X, `Escape` and outside click.
- **Never** open a confirmation from a toast or from another confirmation.
- Use one controlled `open` state per dialog, set by the control that starts the action.

### Copy

| Part                        | Write                                                                               | Not                                                      |
| --------------------------- | ----------------------------------------------------------------------------------- | -------------------------------------------------------- |
| Title                       | "Delete user?" / bulk "Delete 3 users?"                                             | "Are you sure?", "Warning", "Delete", "Delete selected?" |
| Title, unsaved changes      | "Unsaved changes"                                                                   | "Discard changes?"                                       |
| Description                 | "This permanently deletes \{name} and all their access. You can't undo this."       | "This action cannot be undone." with no object named     |
| Description, bulk           | "This permanently deletes 3 users and all their access. You can't undo this."       | Naming only the first user                               |
| Description, reversible     | "\{name} loses access until you reactivate them. Their roles and data are kept."    | Hiding what is kept                                      |
| Confirm                     | "Delete user" / bulk "Delete 3 users"                                               | "OK", "Yes", "Confirm", "Delete", "Delete all"           |
| Cancel                      | "Cancel"                                                                            | "No", "Close", "Back"                                    |
| Footer, unsaved changes     | "Keep editing", "Leave without saving" (both ghost neutral), "Save changes" (brand) | "Cancel"                                                 |
| Type-to-confirm placeholder | `Enter "{name}" to confirm`                                                         | "Type here"                                              |
| Toast                       | "User deleted" / "3 users deleted"                                                  | "Success!", "User was deleted successfully."             |

- Title is `<Verb> <object>?` in sentence case. Confirm repeats that verb and noun without `?`.
- Name the specific object in the description, and end with what can be undone or what is kept. If nothing can be undone, write "You can't undo this."
- If Figma's confirm label differs from the title ("Delete rule?" / "Delete permission"), use the title's noun.

## Examples

A delete confirmation with pending, success and failure handling.

Opened from a row's actions menu, which sets the selected user and the dialog's own `open`
state. While the request runs, `Escape` and outside clicks are ignored; on success the row is
removed.

```tsx
import { useState } from 'react';
import { Badge } from '@wallarm-org/design-system/Badge';
import { Button } from '@wallarm-org/design-system/Button';
import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@wallarm-org/design-system/Dialog';
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuItemText, DropdownMenuTrigger } from '@wallarm-org/design-system/DropdownMenu';
import { Ellipsis } from '@wallarm-org/design-system/icons';
import { Page, PageContent, PageDescription, PageHeader, PageHeaderGroup, PageTitle } from '@wallarm-org/design-system/Page';
import { type TableCellContext, type TableColumnDef, type TableRow, Table } from '@wallarm-org/design-system/Table';
import { useToast } from '@wallarm-org/design-system/Toast';

export const Default = () => {
  const toast = useToast();
  const [users, setUsers] = useState(USERS);
  const [selected, setSelected] = useState<User | null>(null);
  const [deleteOpen, setDeleteOpen] = useState(false);
  const [pending, setPending] = useState(false);

  const renderStatus = ({ row }: TableCellContext<User, unknown>) =>
    row.original.status === 'active' ? (
      <Badge variant='dotted' type='secondary' color='green'>
        Active
      </Badge>
    ) : (
      <Badge variant='dotted' type='secondary' color='gray'>
        Deactivated
      </Badge>
    );

  const renderMenuAction = (row: TableRow<User>) => {
    const user = row.original;
    const handleDeleteSelect = () => {
      setSelected(user);
      setDeleteOpen(true);
    };

    return (
      <DropdownMenu>
        <DropdownMenuTrigger asChild>
          <Button
            variant='ghost'
            color='neutral'
            size='small'
            aria-label={`Actions for ${user.name}`}
            data-testid='users-actions'
          >
            <Ellipsis />
          </Button>
        </DropdownMenuTrigger>
        <DropdownMenuContent>
          <DropdownMenuItem
            variant='destructive'
            onSelect={handleDeleteSelect}
            data-testid='users-delete'
          >
            <DropdownMenuItemText>Delete user</DropdownMenuItemText>
          </DropdownMenuItem>
        </DropdownMenuContent>
      </DropdownMenu>
    );
  };

  const columns: TableColumnDef<User>[] = [
    { accessorKey: 'name', header: 'Name', size: 220, meta: { renderMenuAction } },
    { accessorKey: 'email', header: 'Email', size: 280 },
    { accessorKey: 'role', header: 'Role', size: 180 },
    { accessorKey: 'status', header: 'Status', size: 140, cell: renderStatus },
  ];

  const handleDeleteOpenChange = (next: boolean) => {
    if (!pending) setDeleteOpen(next);
  };

  const handleDelete = async () => {
    if (!selected) return;
    setPending(true);
    try {
      await deleteUser(selected.id);
      setUsers(prev => prev.filter(user => user.id !== selected.id));
      setDeleteOpen(false);
      toast.create({ title: 'User deleted', type: 'default' });
    } catch {
      toast.create({ title: "Couldn't delete user", type: 'error' });
    } finally {
      setPending(false);
    }
  };

  return (
    <Page name='settings-users' fullSize fixedHeight data-testid='users-page'>
      <PageHeader>
        <PageHeaderGroup>
          <PageTitle>Users</PageTitle>
          <PageDescription>
            People who can sign in to your organization, with access set by roles and groups.
          </PageDescription>
        </PageHeaderGroup>
      </PageHeader>

      <PageContent>
        <Table
          aria-label='Users'
          data={users}
          columns={columns}
          getRowId={getUserId}
          data-testid='users-table'
        />
      </PageContent>

      <Dialog
        width={400}
        open={deleteOpen}
        onOpenChange={handleDeleteOpenChange}
        data-testid='delete-user-dialog'
      >
        <DialogContent>
          <DialogHeader>
            <DialogTitle>Delete user?</DialogTitle>
            <DialogDescription>
              This permanently deletes {selected?.name} and all their access. You can't undo this.
            </DialogDescription>
          </DialogHeader>
          <DialogFooter>
            <DialogClose asChild>
              <Button variant='ghost' color='neutral' data-testid='delete-user-cancel'>
                Cancel
              </Button>
            </DialogClose>
            <Button
              color='destructive'
              loading={pending}
              onClick={handleDelete}
              data-testid='delete-user-confirm'
            >
              Delete user
            </Button>
          </DialogFooter>
        </DialogContent>
      </Dialog>
    </Page>
  );
};
```

A state change that grants access uses the default brand confirm.

The description says what the user gets back. Once active, the same button deactivates: that
dialog uses a destructive confirm and says the roles and data are kept.

```tsx
import { useState } from 'react';
import { Button } from '@wallarm-org/design-system/Button';
import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@wallarm-org/design-system/Dialog';
import { Page, PageActions, PageDescription, PageHeader, PageHeaderGroup, PageTitle } from '@wallarm-org/design-system/Page';
import { useToast } from '@wallarm-org/design-system/Toast';

export const Activate = () => {
  const toast = useToast();
  const [status, setStatus] = useState(INACTIVE_USER.status);
  const [open, setOpen] = useState(false);
  const [pending, setPending] = useState(false);

  const isActive = status === 'active';

  const handleOpen = () => setOpen(true);

  const handleOpenChange = (next: boolean) => {
    if (!pending) setOpen(next);
  };

  const handleStatusChange = async () => {
    const nextStatus: UserStatus = isActive ? 'deactivated' : 'active';
    setPending(true);
    try {
      await setUserStatus(INACTIVE_USER.id, nextStatus);
      setStatus(nextStatus);
      setOpen(false);
      toast.create({ title: isActive ? 'User deactivated' : 'User activated', type: 'default' });
    } catch {
      toast.create({ title: "Couldn't update user", type: 'error' });
    } finally {
      setPending(false);
    }
  };

  return (
    <Page name='settings-user' fullSize fixedHeight data-testid='user-page'>
      <PageHeader>
        <PageHeaderGroup className='flex-1'>
          <PageTitle>{INACTIVE_USER.name}</PageTitle>
          <PageDescription>
            {INACTIVE_USER.email} · {INACTIVE_USER.role}
          </PageDescription>
        </PageHeaderGroup>
        <PageActions>
          <Button
            size='medium'
            variant='outline'
            color='neutral'
            onClick={handleOpen}
            data-testid='user-change-status'
          >
            {isActive ? 'Deactivate user' : 'Activate user'}
          </Button>
        </PageActions>
      </PageHeader>

      <Dialog
        width={400}
        open={open}
        onOpenChange={handleOpenChange}
        data-testid='user-status-dialog'
      >
        <DialogContent>
          <DialogHeader>
            <DialogTitle>{isActive ? 'Deactivate user?' : 'Activate user?'}</DialogTitle>
            <DialogDescription>
              {isActive
                ? `${INACTIVE_USER.name} loses access until you reactivate them. Their roles and data are kept.`
                : `${INACTIVE_USER.name} can sign in again with the roles they had before.`}
            </DialogDescription>
          </DialogHeader>
          <DialogFooter>
            <DialogClose asChild>
              <Button variant='ghost' color='neutral'>
                Cancel
              </Button>
            </DialogClose>
            <Button
              color={isActive ? 'destructive' : 'brand'}
              loading={pending}
              onClick={handleStatusChange}
              data-testid='user-status-confirm'
            >
              {isActive ? 'Deactivate user' : 'Activate user'}
            </Button>
          </DialogFooter>
        </DialogContent>
      </Dialog>
    </Page>
  );
};
```

Type-to-confirm omits `width` and keeps confirm disabled until the name matches.

For a delete that also breaks linked objects. The match is exact and case-sensitive, and
closing the dialog resets the input to `''`.

```tsx
import { type ChangeEvent, useState } from 'react';
import { Button } from '@wallarm-org/design-system/Button';
import { Dialog, DialogBody, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@wallarm-org/design-system/Dialog';
import { Input } from '@wallarm-org/design-system/Input';
import { Page, PageActions, PageDescription, PageHeader, PageHeaderGroup, PageTitle } from '@wallarm-org/design-system/Page';
import { useToast } from '@wallarm-org/design-system/Toast';

export const TypeToConfirm = () => {
  const toast = useToast();
  const [open, setOpen] = useState(false);
  const [value, setValue] = useState('');
  const [pending, setPending] = useState(false);

  const handleOpen = () => setOpen(true);

  const handleOpenChange = (next: boolean) => {
    if (pending) return;
    setOpen(next);
    if (!next) setValue('');
  };

  const handleValueChange = (event: ChangeEvent<HTMLInputElement>) => {
    setValue(event.target.value);
  };

  const handleDelete = async () => {
    setPending(true);
    try {
      await deleteProvider(PROVIDER_NAME);
      setOpen(false);
      setValue('');
      toast.create({ title: 'Identity provider deleted', type: 'default' });
    } catch {
      toast.create({ title: "Couldn't delete identity provider", type: 'error' });
    } finally {
      setPending(false);
    }
  };

  return (
    <Page name='settings-sso-provider' fullSize fixedHeight data-testid='provider-page'>
      <PageHeader>
        <PageHeaderGroup className='flex-1'>
          <PageTitle>{PROVIDER_NAME}</PageTitle>
          <PageDescription>SAML identity provider for single sign-on.</PageDescription>
        </PageHeaderGroup>
        <PageActions>
          <Button
            size='medium'
            variant='outline'
            color='destructive'
            onClick={handleOpen}
            data-testid='provider-delete'
          >
            Delete identity provider
          </Button>
        </PageActions>
      </PageHeader>

      <Dialog open={open} onOpenChange={handleOpenChange} data-testid='delete-provider-dialog'>
        <DialogContent>
          <DialogHeader>
            <DialogTitle>Delete identity provider?</DialogTitle>
            <DialogDescription>
              "{PROVIDER_NAME}" is unlinked and deleted, along with its rules. You can't undo this.
            </DialogDescription>
          </DialogHeader>
          <DialogBody>
            <Input
              aria-label='Provider name'
              placeholder={`Enter "${PROVIDER_NAME}" to confirm`}
              value={value}
              onChange={handleValueChange}
              data-testid='delete-provider-input'
            />
          </DialogBody>
          <DialogFooter>
            <DialogClose asChild>
              <Button variant='ghost' color='neutral'>
                Cancel
              </Button>
            </DialogClose>
            <Button
              color='destructive'
              disabled={value !== PROVIDER_NAME}
              loading={pending}
              onClick={handleDelete}
              data-testid='delete-provider-confirm'
            >
              Delete identity provider
            </Button>
          </DialogFooter>
        </DialogContent>
      </Dialog>
    </Page>
  );
};
```

An unsaved-changes guard intercepts the drawer's close and renders the dialog inside `DrawerContent`.

While the form is dirty, the close X, Cancel, `Escape` and an outside click all open the same
dialog. "Keep editing" returns to the form; "Leave without saving" drops the edits.

```tsx
import { type ChangeEvent, useState } from 'react';
import { Button } from '@wallarm-org/design-system/Button';
import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@wallarm-org/design-system/Dialog';
import { Drawer, DrawerBody, DrawerClose, DrawerContent, DrawerFooter, DrawerHeader, DrawerTitle } from '@wallarm-org/design-system/Drawer';
import { Field, FieldLabel } from '@wallarm-org/design-system/Field';
import { Input } from '@wallarm-org/design-system/Input';
import { Page, PageActions, PageDescription, PageHeader, PageHeaderGroup, PageTitle } from '@wallarm-org/design-system/Page';
import { useToast } from '@wallarm-org/design-system/Toast';

export const UnsavedChanges = () => {
  const toast = useToast();
  const [open, setOpen] = useState(false);
  const [guardOpen, setGuardOpen] = useState(false);
  const [savedName, setSavedName] = useState(PROVIDER_NAME);
  const [name, setName] = useState(PROVIDER_NAME);
  const [saving, setSaving] = useState(false);

  const isDirty = name !== savedName;

  const handleOpen = () => setOpen(true);

  const handleDrawerOpenChange = (next: boolean) => {
    if (saving) return;
    if (!next && isDirty) {
      setGuardOpen(true);
      return;
    }
    setOpen(next);
  };

  const handleGuardOpenChange = (next: boolean) => {
    if (!saving) setGuardOpen(next);
  };

  const handleNameChange = (event: ChangeEvent<HTMLInputElement>) => {
    setName(event.target.value);
  };

  const handleLeave = () => {
    setName(savedName);
    setGuardOpen(false);
    setOpen(false);
  };

  const handleSave = async () => {
    setSaving(true);
    try {
      await saveProvider({ name });
      setSavedName(name);
      setGuardOpen(false);
      setOpen(false);
      toast.create({ title: 'Identity provider updated', type: 'default' });
    } catch {
      toast.create({ title: "Couldn't update identity provider", type: 'error' });
    } finally {
      setSaving(false);
    }
  };

  return (
    <Page name='settings-sso-provider' fullSize fixedHeight data-testid='provider-page'>
      <PageHeader>
        <PageHeaderGroup className='flex-1'>
          <PageTitle>{savedName}</PageTitle>
          <PageDescription>SAML identity provider for single sign-on.</PageDescription>
        </PageHeaderGroup>
        <PageActions>
          <Button size='medium' onClick={handleOpen} data-testid='provider-edit'>
            Edit identity provider
          </Button>
        </PageActions>
      </PageHeader>

      <Drawer open={open} onOpenChange={handleDrawerOpenChange} data-testid='edit-provider-drawer'>
        <DrawerContent>
          <DrawerHeader>
            <DrawerTitle>Edit identity provider</DrawerTitle>
          </DrawerHeader>
          <DrawerBody>
            <Field>
              <FieldLabel>Display name</FieldLabel>
              <Input value={name} onChange={handleNameChange} data-testid='provider-name' />
            </Field>
          </DrawerBody>
          <DrawerFooter>
            <DrawerClose asChild>
              <Button variant='ghost' color='neutral'>
                Cancel
              </Button>
            </DrawerClose>
            <Button disabled={!isDirty} loading={saving} onClick={handleSave}>
              Save changes
            </Button>
          </DrawerFooter>

          <Dialog
            open={guardOpen}
            onOpenChange={handleGuardOpenChange}
            data-testid='unsaved-changes-dialog'
          >
            <DialogContent>
              <DialogHeader>
                <DialogTitle>Unsaved changes</DialogTitle>
                <DialogDescription>
                  You have unsaved changes. Leaving will lose them unless you save.
                </DialogDescription>
              </DialogHeader>
              <DialogFooter>
                <DialogClose asChild>
                  <Button variant='ghost' color='neutral' data-testid='unsaved-changes-keep'>
                    Keep editing
                  </Button>
                </DialogClose>
                <Button
                  variant='ghost'
                  color='neutral'
                  onClick={handleLeave}
                  data-testid='unsaved-changes-leave'
                >
                  Leave without saving
                </Button>
                <Button loading={saving} onClick={handleSave}>
                  Save changes
                </Button>
              </DialogFooter>
            </DialogContent>
          </Dialog>
        </DrawerContent>
      </Drawer>
    </Page>
  );
};
```

## States

| State                           | Show                                                  | Example component                   |
| ------------------------------- | ----------------------------------------------------- | ----------------------------------- |
| Idle                            | Question, consequence, Cancel and confirm enabled     | `Dialog`                            |
| Type-to-confirm, empty or wrong | Confirm disabled                                      | `Button disabled={value !== name}`  |
| Type-to-confirm, matches        | Confirm enabled                                       | `Button`                            |
| Pending                         | Spinner on confirm, dialog stays open, close ignored  | `Button loading={pending}`          |
| Success                         | Dialog closes, then a toast                           | `toast.create({ type: 'default' })` |
| Failure                         | Dialog stays open, error toast, confirm enabled again | `toast.create({ type: 'error' })`   |

## What your app owns

- The request, `pending` state, error handling and blocking close while pending.
- Type-to-confirm matching and resetting the input on close.
- Dirty tracking (your form library's flag) and intercepting the drawer close.
- Route changes and tab close from a dirty form: use your router's blocker and `beforeunload`. The design system does not handle them.
- Result toasts: `useToast` from `@wallarm-org/design-system/Toast`, with one `Toaster` at the app root.
- All copy, including entity names.

## Related

- [Action-result toasts](https://wallarm.github.io/design-system/patterns/feedback-toasts.md): the toast after a confirmed action.
- [Entity detail drawer](https://wallarm.github.io/design-system/patterns/detail-drawer.md): opens delete and state-change dialogs from its Actions menu.
- [Create and edit forms](https://wallarm.github.io/design-system/patterns/create-edit-forms.md): forms that need the unsaved-changes guard.
- [Layering](https://wallarm.github.io/design-system/foundations/layering.md): nesting a `Dialog` inside a `Drawer`.
- [Spacing](https://wallarm.github.io/design-system/foundations/spacing.md) and [Typography](https://wallarm.github.io/design-system/foundations/typography.md): the dialog's built-in padding and text styles.
