Questions and approvals an agent puts to the user one at a time before it acts.
import {ApprovalCard} from "@heroui-pro/react";
<ApprovalCard questions={questions}>
<ApprovalCard.Header>
<ApprovalCard.Title />
<ApprovalCard.Dismiss /> {/* Optional */}
</ApprovalCard.Header>
<ApprovalCard.Content>
<ApprovalCard.Options>
{(option) => <ApprovalCard.Option value={option.id} />}
</ApprovalCard.Options>
<ApprovalCard.CustomInput /> {/* Optional: typed answer */}
</ApprovalCard.Content>
<ApprovalCard.Footer>
<ApprovalCard.Steps> {/* Optional */}
{({question}) => <ApprovalCard.Step id={question.id} />}
</ApprovalCard.Steps>
<ApprovalCard.StepCount /> {/* Optional */}
<ApprovalCard.SkippedCount /> {/* Optional */}
<ApprovalCard.Actions>
<ApprovalCard.Skip />
<ApprovalCard.Continue />
</ApprovalCard.Actions>
</ApprovalCard.Footer>
</ApprovalCard>;A question without options asks for approval before one action. Fill the card with what the user is agreeing to.
Continue is always enabled and answers with {selected: []}, so the question's id is in answers. Skip declines it. To deny on Escape, handle onKeyDown on the root. A HeroUI Kbd on each action can show its shortcut; hide it on touch screens.
For an AI SDK tool with needsApproval, send the decision back with addToolApprovalResponse.
<ApprovalCard
questions={[{id: "refund", title: "Refund 3 orders"}]}
onSubmit={({answers}) =>
addToolApprovalResponse({approved: "refund" in answers, id: part.approval.id})
}
/>Define an ask_user tool without execute, render the card when its part reaches input-available, and pass the result to addToolOutput.
const askUser = tool({
description: "Ask the user before acting when a choice is theirs to make.",
inputSchema: z.object({
questions: z.array(
z.object({
multiSelect: z.boolean(),
options: z.array(z.object({description: z.string().optional(), label: z.string()})),
question: z.string(),
}),
),
}),
});A dismissal sends state: "output-error". Set sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithToolCalls on useChat so the run resumes once the output is in. To keep the decision visible after a reload, render a one-line summary for parts in output-available or output-error.
HeroUI follows the BEM methodology to ensure component variants and states are reusable and easy to customize.
The Approval Card component uses these CSS classes:
.approval-card: Root group, also a HeroUI .card.approval-card__header: Title and dismiss button row.approval-card__title: Current question.approval-card__dismiss: Dismiss button in the top-end corner.approval-card__content: Current question, a tab panel while ApprovalCard.Steps is placed.approval-card__options: Radio or checkbox group.approval-card__option-list: Scrolling list with the bottom fade.approval-card__option: Option row.approval-card__option-content: Clickable label that covers the row.approval-card__option-control: Radio or checkbox control.approval-card__option-label: Option label.approval-card__option-description: Option description.approval-card__custom-input: Typed answer.approval-card__footer: Steps, count, and actions row.approval-card__steps: Tab list of step dots.approval-card__step: Step dot.approval-card__step-count: "2/3" count.approval-card__step-count-current: Current number in the count.approval-card__skipped-count: "N skipped" next to the count on the last question.approval-card__actions: Skip and Continue.approval-card__skip: Skip button, size="sm".approval-card__continue: Continue or Send button, size="sm".approval-card__continue-label: Continue or Send label, or the text a Continue function returns, sized to the wider of the two[data-hovered] on .approval-card__step (dot color), and [data-hovered="true"] on .approval-card__option-content (row fill on .approval-card__option)[data-focus-visible] on .approval-card__step (focus ring)[data-current] on .approval-card__step: Current question, drawn as a pill[data-answered] on .approval-card__step: Answered question[data-edge] on .approval-card__step: Smaller dot at the edge of the window of maxVisible dots[data-hidden] on .approval-card__step: Outside the window[data-single] on .approval-card__steps and .approval-card__step-count: The card has one question[data-last-step] on .approval-card__skipped-count: The last question is shown[data-empty] on .approval-card__skipped-count: No other question is unanswered. The count is hidden unless [data-last-step] is set and [data-empty] is not[data-swapped] on .approval-card__title, .approval-card__content, .approval-card__skipped-count, and .approval-card__continue-label: Shown after a question change, which plays the enter transition--approval-card-color-duration, --approval-card-color-ease: Step dot color (default: 150ms, var(--ease-smooth))--approval-card-swap-duration, --approval-card-swap-ease: Question change fade (default: 200ms, var(--ease-out-quint))--approval-card-swap-offset, --approval-card-swap-blur: Rise and blur a new question starts from (default: calc(var(--spacing) * 1), 2px)--approval-card-step-duration, --approval-card-step-ease: Step dot width (default: var(--approval-card-swap-duration), var(--ease-in-out-quart))--approval-card-reduced-duration: Question change fade under prefers-reduced-motion: reduce, where a new question fades in without moving or blurring and the dots switch width at once while their color still fades (default: 120ms)--approval-card-options-max-height: Height before the list scrolls (default: calc(var(--spacing) * 48))--approval-card-fade-size: Fade at the scrolling edge (default: calc(var(--spacing) * 6))--approval-card-control-size: Radio or checkbox size, used to center it on the first label line (default: calc(var(--spacing) * 4))--approval-card-dot-answered: Answered dot color, also used to hover an unanswered dot (default: color-mix(in oklab, var(--color-muted) 45%, transparent))--approval-card-dot-size, --approval-card-pill-width, --approval-card-edge-size: Dot, current pill, and edge dot sizes (default: calc(var(--spacing) * 1.5), calc(var(--spacing) * 5), calc(var(--spacing) * 1))--approval-card-step-hit-size, --approval-card-step-gap: Step hit area height and gap (default: calc(var(--spacing) * 6), calc(var(--spacing) * 1.5))Wraps HeroUI Card. Supports native div props.
Continue waits for an answer and reads Send on the last question. Skip clears the answer, calls onSkip, and moves on, or sends on the last question. The dismiss button calls onDismiss, and your app ends the set. onSubmit receives {answers, skipped}, where answers holds only the answered questions.
Without children, the card renders the Anatomy layout, with Dismiss only when onDismiss is set and Steps and StepCount only for more than one question. With children, it renders only the parts you place. Header, Content, Footer, and Actions render only their children; Options and Steps render one item per option or question unless you pass children. Placed parts render for any question count, so gate Steps and StepCount with questions.length > 1 or hide them with [data-single]. The card fills its container, so set a width, such as max-w-100.
| Prop | Type | Default | Description |
|---|---|---|---|
questions | ApprovalCardQuestion[] | - | Questions asked one at a time |
value | ApprovalCardValue | - | Answers when controlled |
defaultValue | ApprovalCardValue | {} | Initial answers when uncontrolled |
onChange | (value: ApprovalCardValue) => void | - | Called on every answer change |
currentStep | number | - | Index of the shown question when controlled |
defaultStep | number | 0 | Index of the first shown question when uncontrolled |
onStepChange | (step: number) => void | - | Called when the shown question changes |
onSubmit | (result: ApprovalCardSubmitResult) => void | - | Called by Send, or by Skip on the last question |
onSkip | (questionId: string) => void | - | Called with the id of a skipped question |
onDismiss | () => void | - | Called by the dismiss button |
variant | "transparent" | "default" | "secondary" | "tertiary" | "default" | Card variant |
children | ReactNode | - | Replaces the default layout with the placed parts |
render | DOMRenderFunction | - | Custom render function to override the default div element |
The current question's title, or its children. While placed, it labels the card and the options. Supports native div props.
The card is a group labelled by ApprovalCard.Title. Without a placed Title, the card takes the question's title as its aria-label. The title is not a heading, so the chat keeps its outline.
Extends HeroUI CloseButton props. Renders an X labelled "Dismiss" and calls onDismiss on press. In ApprovalCard.Header, it sits in the card's top-end corner like the HeroUI Modal close button, and the title keeps clear of it. The default layout renders it only when onDismiss is set.
Extends HeroUI RadioGroup props in "single" mode and CheckboxGroup props in "multiple" mode, with variant="secondary". The card owns the answer and the markup, so value, defaultValue, onChange, validate, and render are left out, and className and style take plain values. Renders nothing when the question has no options.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | ((option: ApprovalCardOptionItem) => ReactNode) | - | ApprovalCard.Option elements, or a function that renders one for each option of the shown question. One per option by default |
Extends HeroUI Radio props in "single" mode and Checkbox props in "multiple" mode, without render and with plain className and style.
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | - | Id of an option of the current question |
children | ReactNode | - | Replaces the label; the control and the description stay |
Extends HeroUI Input props except value and defaultValue, which the card controls, with variant="secondary", placeholder="Something else…", and aria-label="Other answer". Renders when the question sets allowCustom.
Shown on the last question when others have no answer; otherwise it stays mounted and CSS hides it through [data-last-step] and [data-empty]. Supports native div props.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | ((renderProps: ApprovalCardSkippedCountRenderProps) => ReactNode) | - | Replaces the default "N skipped" |
ApprovalCardSkippedCountRenderProps is {count}.
Tab list labelled "Questions". While placed, the content becomes its tab panel; without it, the content is a plain container with no tab roles. It renders for any question count and sets [data-single] for one question. Supports native div props.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | ((renderProps: ApprovalCardStepRenderProps) => ReactNode) | - | ApprovalCard.Step elements, or a function that renders one for each question. One Step per question by default |
maxVisible | number | 7 | Dots shown at once; past it, the window follows the current question |
ApprovalCardStepRenderProps is {index, isAnswered, question}, with a 0-based index.
Supports native div props. Its aria-label defaults to "Question 2, answered" or "Question 2, not answered".
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | - | Id of the question |
Shows "2/3" and announces "Question 2 of 3" in a polite live region. It renders for any question count and sets [data-single] for one question. Supports native div props.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | ((renderProps: ApprovalCardStepCountRenderProps) => ReactNode) | - | Replaces the announced "Question 2 of 3"; the visible "2/3" stays |
ApprovalCardStepCountRenderProps is {current, total}, the 1-based number of the shown question and the question count.
Extends HeroUI Button props, with variant="ghost" and size="sm". Children replace "Skip". Hidden when the question sets allowSkip: false.
Extends HeroUI Button props, with variant="primary" and size="sm". Disabled until the question is answered. On a confirmation it is always enabled and answers with {selected: []}.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | ((renderProps: ApprovalCardContinueRenderProps) => ReactNode) | - | Replaces "Continue" and "Send" |
ApprovalCardContinueRenderProps is {isLastStep}. When the function returns text, the button keeps the width of the wider label, so Skip stays in place on the last question.
Layout parts that render only their children. Support native div props.
| Field | Type | Default | Description |
|---|---|---|---|
id | string | - | Unique id, used as the key in ApprovalCardValue |
title | string | - | Question shown in the header |
options | ApprovalCardOptionItem[] | - | Optional. Options in order; keys 1 to 9 pick them. Without options or allowCustom, the question is a confirmation that Continue approves and Skip declines |
selectionMode | "single" | "multiple" | "single" | Pick one option or several. In "single" mode, typing a custom answer clears the radio and picking a radio clears the text. In "multiple" mode, the typed answer is sent with the ticked options |
allowCustom | boolean | false | Shows a text field for an answer that isn't listed |
allowSkip | boolean | true | Shows Skip |
ApprovalCardOptionItem is {id, label, description?}. ApprovalCardValue maps question ids to {selected, custom?}, the picked option ids and the typed answer. ApprovalCardSubmitResult is {answers, skipped}, the answered questions with the typed answer trimmed and the ids of the rest in order.
| Default text | Where | Override |
|---|---|---|
| "Continue", "Send" | ApprovalCard.Continue | Function child receiving {isLastStep} |
| "Skip" | ApprovalCard.Skip | Children |
| "Something else…" | ApprovalCard.CustomInput placeholder | placeholder |
| "N skipped" | ApprovalCard.SkippedCount | Function child receiving {count} |
| "Dismiss" (announced) | ApprovalCard.Dismiss | aria-label |
| "Other answer" (announced) | ApprovalCard.CustomInput | aria-label |
| "Questions" (announced) | ApprovalCard.Steps | aria-label |
| "Question 2, answered", "Question 2, not answered" | ApprovalCard.Step | aria-label on each Step; a function child of Steps receives {index, isAnswered, question} |
| "Question 2 of 3" (announced) | ApprovalCard.StepCount | Function child receiving {current, total} |
Passing children to ApprovalCard replaces the default layout, so place every part you still need when you override a string.
<ApprovalCard questions={questions} onDismiss={onDismiss}>
<ApprovalCard.Header>
<ApprovalCard.Title />
<ApprovalCard.Dismiss aria-label={t("approval.dismiss")} />
</ApprovalCard.Header>
<ApprovalCard.Content>
<ApprovalCard.Options />
<ApprovalCard.CustomInput
aria-label={t("approval.otherLabel")}
placeholder={t("approval.other")}
/>
</ApprovalCard.Content>
<ApprovalCard.Footer>
<ApprovalCard.Steps aria-label={t("approval.questions")}>
{({index, isAnswered, question}) => (
<ApprovalCard.Step
aria-label={t("approval.step", {answered: isAnswered, number: index + 1})}
id={question.id}
/>
)}
</ApprovalCard.Steps>
<ApprovalCard.StepCount>
{({current, total}) => t("approval.stepCount", {current, total})}
</ApprovalCard.StepCount>
<ApprovalCard.SkippedCount>
{({count}) => t("approval.skipped", {count})}
</ApprovalCard.SkippedCount>
<ApprovalCard.Actions>
<ApprovalCard.Skip>{t("approval.skip")}</ApprovalCard.Skip>
<ApprovalCard.Continue>
{({isLastStep}) => t(isLastStep ? "approval.send" : "approval.continue")}
</ApprovalCard.Continue>
</ApprovalCard.Actions>
</ApprovalCard.Footer>
</ApprovalCard>| Key | Action |
|---|---|
| Arrow keys, Home, End | Move between questions while ApprovalCard.Steps is placed |
| 1 to 9 | Pick an option by position while focus is in the card, except in a text field. Skips disabled options and options not rendered |
| Enter | On an option or in the custom input, acts as Continue, or Send on the last question. Does nothing while Continue is disabled |
| Cmd+Enter, Ctrl+Enter | Acts as Continue anywhere in the card, including text fields, while Continue is enabled |
onKeyDownCapture calls preventDefault.onKeyDown on the root.Resources