Skip to content
EspañolEnglish
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.
  • questions are the questions: { key, prompt, options, multiple?, allowOther?, required? }. All are required unless said otherwise.
  • onSubmit receives 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: FormRepeatableField and 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

Which customers do we warn?
Through which channels?Pick as many as you like

0 of 2 answered

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.

PropTypeWhat it does
labelrequiredstringWhat is being asked: "Before starting". Required: it is the name of the form.
onSubmitrequired(answers: Answers) => voidCalled with the answers when every required one is answered.
questionsrequiredreadonly Question[]—
classNamestringMerged with the library classes; it does not replace them.
disabledbooleanAlready sent or cannot be changed.
submitLabelstringThe 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: