Components · Overlays
AlertDialog
A small centered confirmation with the alertdialog role, for the few confirmations a product lists; every other confirmation is a Dialog at size sm.
import { AlertDialog } from "@botiverse/raft-ui";An alert dialog asks people to confirm an action before it happens, with the alertdialog role, so a screen reader announces it as an interruption. Most confirmations aren't built on it: a confirmation is a Dialog at size="sm", deleting and stopping included, and a product lists the few that use AlertDialog instead (Choosing a component, 2026-11-03). In Raft Chat there are two: discarding unsaved edits to an agent's profile, and opening a link that hands off to another app (Raft Chat). It is a 400px dialog on a scrim, the width of every confirmation, with a title, a sentence on what will happen, Cancel and a confirm button whose color states the consequence.
When to use
Anatomy
AlertDialog: the root. Required.AlertDialogTrigger: the button that opens it. Usually the dialog is opened from a menu item instead.AlertDialogContent: the centered surface, at most 400px wide, the width of asize="sm"Dialog, so every confirmation is one width, with the scrim (AlertDialogOverlay) behind it. Required.AlertDialogHeader: the title row, with an optionalAlertDialogClose(×).AlertDialogTitle: the title. Required.AlertDialogBody: the content under the header, in the base ink (foreground).AlertDialogDescription: what will happen, inforeground-muted. It takes only aHelperText, made withhelperText(content, { why, about }), and renders itswhyandaboutasdata-whyanddata-about; a confirmation's line is usuallyconsequence(Writing › Helper text).AlertDialogFooter: the buttons in one row at the end, Cancel then the commit button, on a phone as on a desktop. Only when they don't fit on one line do they stack full width, the commit button on top and Cancel framed, as in Dialog.AlertDialogCancel: a ghost button that closes the dialog; framed when the buttons stack. Required.AlertDialogAction: the confirm button. It is a Button and doesn't close the dialog by itself: close it when the action finishes.AlertDialogPortal: a lower-level part.
Variants
The confirm button's color says what happens, the same in a confirmation built on Dialog:
Deleting something large, such as an agent or a server, also asks for its name to be typed (Forms). That confirmation is a size="sm" Dialog, not an AlertDialog: its example is in Dialog.
Behavior
- It appears and disappears without animation, over the scrim, like every centered dialog (Dialog).
- Mounted already open (
openordefaultOpen), it opens one commit after it mounted, before the first paint, as Dialog, Drawer and Lightbox do, so a confirmation mounted open together with one of them still stacks in its order over them (#proj-frontend:#121). - Esc and Cancel close it without acting.
Content
- Title it with the words of the button that opened it and a question mark, since it only asks whether to go on: Delete box opens Delete box? (Writing).
- Say in one or two sentences what happens, in plain words: "Box leaves every channel."
- Label the confirm button with the title's verb: Stop for Stop Wug?. Keep the object when it can't be undone, on the red button: Delete agent. Label the other button Cancel (Writing).
Accessibility
- AlertDialog wraps the Base UI Dialog and sets the
alertdialogrole, so screen readers announce it as an interruption. Base UI provides the focus trap, Esc and focus return. AlertDialogTitleis the accessible name andAlertDialogDescriptionthe description. Put the consequence inAlertDialogDescription, so it is announced with the title.- The × of
AlertDialogCloseis labeled "Close".
Rules
- Put Cancel on the left and the confirm button on the right, and no other buttons.
- Don't color the menu item that opens the dialog: the confirm button carries the color (Feedback).
API
AlertDialog
AlertDialogAction
Also takes the attributes of its element.
AlertDialogBody
Takes the attributes of its element.
AlertDialogCancel
Also takes the attributes of its element.
AlertDialogClose
Also takes the attributes of its element.
AlertDialogContent
Also takes the attributes of its element.
AlertDialogDescription
Also takes the attributes of its element.
AlertDialogFooter, AlertDialogHeader
Takes the attributes of its element.
AlertDialogOverlay
Also takes the attributes of its element.
AlertDialogPortal
Also takes the attributes of its element.
AlertDialogTitle
Also takes the attributes of its element.
AlertDialogTrigger
Also takes the attributes of its element.
Related
Changes
- 0.103.0 · Breaking ChangesExplanation slots take only a
HelperText:FieldDescription,FormSection'sdescription, aChoiceListitem'sdescription,SelectItemDescription,DialogDescription,AlertDialogDescription,DrawerDescription,PopoverDescription,EmptyStateDescription,CardDescription,CardFooter,BannerDescription,DialogFooterNote(work in progress),MessageActionCardHint,MessageActionCardHeaderDescription,MessageActionCardScopeDescriptionandMessageActionCardActionsNote. AHelperTextis made only byhelperText(content, { why, about }):contentis anyReactNode(a string, a formatted message, aTextLinkinside a sentence),whyis"consequence","audience"or"recovery", andaboutnames the thing the line is about. Each slot renders the content withdata-whyanddata-about, and in development warns once when it is given anything else, which it still renders.ToastDescription,NotificationCenterItemBody,EmptyStateTitle,ListRowDescriptionand the status and data parts are unchanged. - 0.103.0 · Changed
DialogBodyandAlertDialogBodydraw their text inforeground, notforeground-muted. - 0.23.0 · ChangedButton
variant="ghost", so DialogFooter, AlertDialogFooter (AlertDialogCancel) and DrawerActions: a ghost text button inside an element withdata-stackedtakes the ink frame ofdefault. Dialog and alert dialog footers setdata-stackedonly while their buttons stack;DrawerActionssets it in a bottom or top sheet, where its buttons are always stacked, and not in a drawer from a side. Keep writing Cancel asghost. - 0.8.3 · FixedA
DialogorAlertDialogopened from a sheet or another dialog draws its own, lighter scrim, so it no longer sits undimmed on the surface below. A sheet opened from a dialog does the same; a sheet over a sheet is unchanged. Nesting follows the modal roots, as in Base UI, and amodal={false}parent doesn't count.