XDSAlertDialog@xds/core · AlertDialog

Usage

AlertDialog asks the user to confirm a destructive or irreversible action before it happens. Use it for things like deleting content, revoking access, or discarding unsaved changes. For cases where you want to show an alert without managing open state, use the `useXDSImperativeAlertDialog` hook — call `alert.show(options)` and render `alert.element` in your tree.

Best practices

GuidancePractices
DoMake the action button label specific — "Delete project" is better than "OK" or "Confirm".
DoDescribe what will happen in the description so the user knows the consequences before confirming.
Don'tUse AlertDialog for non-destructive actions — use a standard Dialog instead.

Import

ts
import {XDSAlertDialog} from '@xds/core/AlertDialog'

Props

PropTypeDescription
isOpenrequired
booleanWhether the dialog is open.
onOpenChangerequired
(isOpen: boolean) => unknownVisibility change callback.
titlerequired
stringDialog title. Linked via aria-labelledby.
descriptionrequired
stringConsequence description. Linked via aria-describedby.
actionLabelrequired
stringAction button label.
onActionrequired
() => unknownCalled when action button is clicked. Does NOT auto-close.
cancelLabel
string (default: 'Cancel')Cancel button label.
actionVariant
XDSButtonVariant (default: 'destructive')Action button variant.
isActionLoading
booleanShows loading spinner on the action button.
width
number | string (default: 400)Dialog width.
isInline
boolean (default: false)Renders alert dialog content inline without modal behavior. For documentation previews and showcases only.

Sub-components

AlertDialog is a compound component with 2 sub-components.

XDSAlertDialog

A modal dialog that asks the user to confirm a destructive action.
PropTypeDescription
isOpenrequired
booleanWhether the dialog is open.
onOpenChangerequired
(isOpen: boolean) => unknownVisibility change callback.
titlerequired
stringDialog title. Linked via aria-labelledby.
descriptionrequired
stringConsequence description. Linked via aria-describedby.
actionLabelrequired
stringAction button label.
onActionrequired
() => unknownCalled when action button is clicked. Does NOT auto-close.
cancelLabel
string (default: 'Cancel')Cancel button label.
actionVariant
XDSButtonVariant (default: 'destructive')Action button variant.
isActionLoading
booleanShows loading spinner on the action button.
width
number | string (default: 400)Dialog width.
isInline
boolean (default: false)Renders alert dialog content inline without modal behavior. For documentation previews and showcases only.

useXDSImperativeAlertDialog

Hook for showing an alert dialog without managing open state. Call alert.show(options) to open and alert.hide() to close. Render alert.element in your JSX tree.
PropTypeDescription
show
(options: AlertDialogOptions) => voidShow the alert dialog with the given options. Options are the same as XDSAlertDialog props minus isOpen/onOpenChange.
hide
() => voidHide the alert dialog.
isOpen
booleanWhether the dialog is currently open.
element
ReactNodeThe dialog element — render this in your JSX tree.

Examples

Common configurations, variations, and states.
AlertDialog — LoadingA confirmation dialog that shows a spinner while the action runs.
tsx
'use client';
import {useState} from 'react';
import {XDSAlertDialog} from '@xds/core/AlertDialog';
export default function AlertDialogAsyncAction() {
const [isLoading, setIsLoading] = useState(false);
return (
<XDSAlertDialog
isOpen
isInline
onOpenChange={() => {}}
title="Revoke access?"
description="This user will immediately lose access to all shared resources."
actionLabel="Revoke"
isActionLoading={isLoading}
onAction={async () => {
setIsLoading(true);
await new Promise(r => setTimeout(r, 2000));
setIsLoading(false);
}}
/>
);
}

Showcase source

tsx
'use client';
import {
XDSAlertDialog,
useXDSImperativeAlertDialog,
} from '@xds/core/AlertDialog';
// Remove isInline for production — alert dialogs should be modal.
export default function AlertDialogDeleteConfirmation() {
const alert = useXDSImperativeAlertDialog();
const alertProps = {
title: 'Delete item?',
description:
'This action cannot be undone. The item and all its data will be permanently removed.',
actionLabel: 'Delete',
} as const;
return (
<>
<XDSAlertDialog
isOpen
isInline
onOpenChange={() => {}}
{...alertProps}
onAction={() =>
alert.show({...alertProps, onAction: () => alert.hide()})
}
/>
{alert.element}
</>
);
}