Approval Question
A host-controlled single- or multiple-choice question flow with stable answer ids, explicit navigation, skip, and submit callbacks.
A controlled, single- or multiple-choice question for collecting user input during a chat turn. The host supplies question data, stable ids, current answers and navigation callbacks. Submitting answers does not approve or execute a tool; use an AgentTimeline approval block for an explicit tool decision.
Import
import { ApprovalQuestion } from "@yuhuanowo/yunui/ai";Example
This preview uses local state and host fixtures only; it sends no request.
Approval Question
Question 1 of 2
Which sources should I check?
Answers stay in this local preview.
Data and state
Use stable question and option ids. For a single question the component returns one selected option id; for multiple it returns the selected ids. The optional other choice has its own stable id and stores its text in the same answer entry.
import { useState } from "react";import { ApprovalQuestion, type ApprovalQuestionAnswers, type ApprovalQuestionData,} from "@yuhuanowo/yunui/ai";
const questions: ApprovalQuestionData[] = [The host owns every answer and the active question. The panel advances only after the user chooses Next and the host's onActiveQuestionChange updates activeQuestionId. onSkip and onSubmit are separate host callbacks; without onSubmit, the final Submit button is disabled. An onDismiss callback adds a Dismiss control, but the host must use its state (for example, conditionally rendering the panel from questionOpen) to hide or restore it. Dismiss never submits an answer. submitting and disabled freeze all controls, including Dismiss. labels localizes the buttons, progress(current, total), the other-choice placeholder and the submitting/dismiss labels.
Tool approvals are separate
An ApprovalQuestion collects a response or clarification. Dismiss only closes it when the host changes its rendering state; it does not approve, reject or submit. It is not an authorization result. Render a tool-decision row with AgentTimeline and wire onApprove / onReject only when the host can perform that decision.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| activeQuestionId* | string | — | The host controls which stable question ID is visible. |
| answers* | Readonly<Record<string, ApprovalQuestionAnswer>> | — | Controlled answers keyed by stable question ID, containing stable option IDs. |
| className | string | — | |
| disabled | boolean | false | Host-controlled read-only state. |
| labels | ApprovalQuestionLabels | — | |
| onActiveQuestionChange | ((id: string) => void) | — | |
| onAnswersChange* | (answers: Readonly<Record<string, ApprovalQuestionAnswer>>) => void | — | |
| onDismiss | (() => void) | — | Requests dismissal; the host decides whether to hide or cancel this question. |
| onSkip | ((questionId: string) => void) | — | |
| onSubmit | ((answers: Readonly<Record<string, ApprovalQuestionAnswer>>) => void) | — | |
| questions* | readonly ApprovalQuestionData[] | — | |
| submitting | boolean | false | Host-controlled request in flight; choices and navigation are disabled until it changes. |