All components (283)
Questionnaire
AI · Questionnaire
What it is and when to use it
The questions an assistant asks a person before going on: with options, single or multiple choice, and with their "other answer".
When to use it
- An agent needs decisions before acting and prefers closed questions to free text.
questionsare the questions:{ key, prompt, options, multiple?, allowOther?, required? }. All are required unless said otherwise.onSubmitreceives the answers by key: the list of chosen options and, if "other" was chosen, what was typed.
When not to
- A form with text, date or number fields:
FormRepeatableFieldand the form fields. - A single yes-or-no question:
ConfirmAction.
Keyboard: inside each question, the arrows move the choice (single) or Space ticks (multiple); Enter on the button sends.
Accessibility: each question is a group with a name. It does not let you send until the required ones are answered and then says which is missing, with text and in an alert; the error does not depend on colour.
Fine-tuning: amset-questionnaire and the amset-questionnaire__* classes.
What it looks like
You haven't answered yet.
<Questionnaire
label="Before starting"
questions={[
{ key: "scope", prompt: "Which customers do we warn?", options: alcance, allowOther: true },
{ key: "channels", prompt: "Through which channels?", multiple: true, options: canales },
]}
onSubmit={(respuestas) => seguir(respuestas)}
/>Props
Import it with import { Questionnaire } from '@amset/ui'. Required props are marked.
| Prop | Type | What it does |
|---|---|---|
labelrequired | string | What is being asked: "Before starting". Required: it is the name of the form. |
onSubmitrequired | (answers: Answers) => void | Called with the answers when every required one is answered. |
questionsrequired | readonly Question[] | — |
className | string | Merged with the library classes; it does not replace them. |
disabled | boolean | Already sent or cannot be changed. |
submitLabel | string | The text of the button. "Send answers" by default. |
It also accepts the attributes of the element it renders: className, style, data-*, aria-* and its events.
In the test bench
Every state and variant, to try one at a time, on its page at storybook.amsetui.com:
