Alert dialog: Async action
Return a promise from the onClick of <AlertDialogAction />. The button shows a spinner and the dialog can’t be closed until the promise settles. It closes when it resolves and stays open when it rejects, so people can try again.
This adds the example as components/examples/alert-dialog/async-action.tsx, together with the Alert dialog component and the HextaUI theme tokens it needs.
pnpm dlx shadcn@latest add https://hextaui.com/r/alert-dialog-async-action.jsonTo add only the component, follow the Alert dialog installation.
Props in this example
The Alert dialog props this example sets, from the API reference.
| Prop | Type | Default |
|---|---|---|
onOpenChangeNot called for closes blocked by a pending action. | (open: boolean, details) => void | – |
| Prop | Type | Default |
|---|---|---|
render | ReactElement | (props, state) => ReactElement | <button> |
| Prop | Type | Default |
|---|---|---|
variant | "default" | "destructive" | "default" |
| Prop | Type | Default |
|---|---|---|
onClickReturn a promise to show a spinner and keep the dialog open until it settles. Call event.preventDefault() to keep it open. | (event) => void | PromiseLike<unknown> | – |
variant | ButtonVariant | "default" |
Every prop is in the Alert dialog API reference.
See them all, with keyboard support and accessibility notes, on the Alert dialog page.
- ButtonButtons in every variant and size, with a built-in loading, success and error flow that skips the spinner for fast requests.
- SheetA panel that slides in from any edge, with swipe-to-dismiss, scroll lock and stacked nesting.
- CommandA searchable list of actions, inline or as a ⌘K palette, with pages, shortcuts and highlighted matches.
- Context menuA menu of actions on right click or long press, with submenus, checkbox and radio items, and hold feedback on touch.
- DialogA window over the page for forms and focused tasks, with a pinned header and footer, nesting, and a swipeable bottom sheet on phones.
- DrawerA panel that slides in from any edge and follows your finger, with snap points, a working handle and nested drawers that stack.