Questionnaire
A composable multi-step form for fixed, multiple, freeform, and optional answers.
Questionnaire coordinates ordered questions, answer state, validation, progress, and navigation while leaving persistence, transport, cancellation, and its surrounding card or dialog to the application.
Import
Section titled “Import”import { Questionnaire } from "@zentara-co/zenos-ui";Composition
Section titled “Composition”Define the ordered item metadata once on the root, then compose the visible content with compound parts. The root uses each item definition to determine required validation, multiple selection, disabled navigation, and progress.
const items = [ { name: "scope", required: true }, { name: "checks", multiple: true }, { name: "notes" },] as const; <Questionnaire items={items} onSubmit={handleSubmit}> <Questionnaire.Progress /> <Questionnaire.Item name="scope"> <Questionnaire.Title>What may change?</Questionnaire.Title> <Questionnaire.Description>Choose one scope.</Questionnaire.Description> <Questionnaire.Choices> <Questionnaire.Choice value="component">The component</Questionnaire.Choice> <Questionnaire.Choice value="feature">The complete feature</Questionnaire.Choice> <Questionnaire.Input aria-label="Another scope" placeholder="Describe another scope…" /> </Questionnaire.Choices> <Questionnaire.Error /> </Questionnaire.Item> <Questionnaire.Actions> <Questionnaire.Previous /> <Questionnaire.Skip /> <Questionnaire.Next /> <Questionnaire.Submit>Save plan</Questionnaire.Submit> </Questionnaire.Actions></Questionnaire>;Answer types
Section titled “Answer types”An item without multiple renders its choices as native radio controls. Set multiple: true to render native checkboxes and store a string array. Questionnaire.Input supplies a freeform string answer and clears a previously selected fixed choice for that item.
Required and optional items
Section titled “Required and optional items”Set required: true on an item definition to block forward navigation until it has an answer. Questionnaire.Error renders the validation message and associates it with the active fieldset. Optional items expose Questionnaire.Skip before the final item; skipping removes any existing answer for that item.
Controlled state
Section titled “Controlled state”Use value, defaultValue, and onValueChange for the active item. Use answers, defaultAnswers, and onAnswersChange when the host needs to restore a draft, validate externally, or persist changes as they happen.
<Questionnaire items={items} value={activeItem} onValueChange={setActiveItem} answers={answers} onAnswersChange={setAnswers}> {/* questionnaire parts */}</Questionnaire>Custom progress
Section titled “Custom progress”Questionnaire.Progress accepts a render function when the product needs different wording or a visual progress treatment.
<Questionnaire.Progress> {({ current, itemCount }) => `Checkpoint ${current} of ${itemCount}`}</Questionnaire.Progress>Questionnaire.Root Questionnaire.Progress Questionnaire.Item Questionnaire.Title Questionnaire.Description Questionnaire.Choices Questionnaire.Choice Questionnaire.Input Questionnaire.Error Questionnaire.Actions Questionnaire.Previous Questionnaire.Skip Questionnaire.Next Questionnaire.Submit
API
| Prop | Type | Default | Description |
|---|---|---|---|
items | readonly QuestionnaireItemDefinition[] | — | Ordered question metadata used for navigation, validation, and input type. |
value / defaultValue | string | — | Controlled or initial active item name. |
onValueChange | (value: string) => void | — | Runs when navigation changes the active item. |
answers / defaultAnswers | QuestionnaireAnswers | — | Controlled or initial string and string-array answers. |
onAnswersChange | (answers: QuestionnaireAnswers) => void | — | Runs with the complete answer collection after an answer changes. |
onSubmit | (event, answers) => void | — | Runs after the final active item passes validation. |
Item.name | string | — | Matches an item definition and supplies the native form field name. |
Choice.value | string | — | Value stored by the native radio or checkbox control. |
Input.onValueChange | (value: string) => void | — | Runs when the freeform answer changes. |
native props | React.FormHTMLAttributes<HTMLFormElement> | — | Forwards native attributes, events, aria-*, data-*, className, style, and ref. |
Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props,
including className, style, aria-*, and data-*.
Accessibility
Section titled “Accessibility”Each item is a native fieldset, and its title is a legend. Fixed answers preserve native radio and checkbox behavior. Descriptions and active errors are associated with the fieldset, progress is exposed as a named progress bar, and navigation uses native buttons. Successful navigation focuses the new question; failed required validation focuses the first available answer. Always give Questionnaire.Input a visible label, aria-label, or aria-labelledby; a placeholder is not an accessible name.