Skip to content
WebJs
Menu

Questionnaire

Build accessible, multi-step questionnaires with single, multiple, freeform, and intentionally skipped answers.

<ui-questionnaire> is a form element for presenting one question at a time. It manages answers, progress, validation, and navigation.

It works well for agent clarification prompts, onboarding, surveys, intake forms, and configuration.

The parts are custom elements that apply the kit's classes, and a class written on any part is merged onto the element that part renders, so you restyle it by adding classes, or by editing the copy the CLI puts in your project. For the themed examples, see Questionnaire.

Installation

The elements ship in the Questionnaire component file. Adding it copies components/ui/questionnaire.ts into your project, together with the Button its navigation actions are styled with.

pnpm dlx @webjsdev/ui add questionnaire

Import

import '#components/ui/questionnaire.ts';

Importing the file registers every part as its own element. Each part takes the attributes listed in the API Reference, plus a class that is merged onto the element it renders.

Anatomy

<ui-questionnaire>
  <ui-questionnaire-progress></ui-questionnaire-progress>
  <ui-questionnaire-item name="question">
    <ui-questionnaire-title></ui-questionnaire-title>
    <ui-questionnaire-description></ui-questionnaire-description>
    <ui-questionnaire-choices>
      <ui-questionnaire-choice value="answer">
        Label
        <ui-questionnaire-choice-description></ui-questionnaire-choice-description>
      </ui-questionnaire-choice>
      <ui-questionnaire-input></ui-questionnaire-input>
    </ui-questionnaire-choices>
    <ui-questionnaire-error></ui-questionnaire-error>
  </ui-questionnaire-item>
  <ui-questionnaire-actions>
    <ui-questionnaire-previous></ui-questionnaire-previous>
    <ui-questionnaire-skip></ui-questionnaire-skip>
    <ui-questionnaire-next></ui-questionnaire-next>
    <ui-questionnaire-submit></ui-questionnaire-submit>
  </ui-questionnaire-actions>
</ui-questionnaire>

<ui-questionnaire> renders a form. Each <ui-questionnaire-item> renders a fieldset, and its <ui-questionnaire-title> renders the legend. <ui-questionnaire-choice> renders a label around a native radio or checkbox, the indicator and the shortcut hint, all from one element.

Styled version

The kit has one version, and it is styled. Its parts are these elements:

ElementPart
<ui-questionnaire>The root form.
<ui-questionnaire-progress>The progress line.
<ui-questionnaire-item>One step, rendered as a fieldset.
<ui-questionnaire-title>The step's question, rendered as the legend.
<ui-questionnaire-description>Supporting text for the step.
<ui-questionnaire-choices>The list of choices.
<ui-questionnaire-choice>One choice: the native input, its label and its shortcut hint.
<ui-questionnaire-choice-description>A second line inside a choice.
<ui-questionnaire-input>A free-text answer.
<ui-questionnaire-error>The step's validation message.
<ui-questionnaire-actions>The layout container for the buttons.
<ui-questionnaire-previous>, <ui-questionnaire-skip>, <ui-questionnaire-next>, <ui-questionnaire-submit>The navigation buttons.

Basic usage

Each item is one step. Its name identifies the step and becomes the form field name for its answers. A choice's value is the submitted answer.

What should the agent build next?

Choose a direction or describe another task.

What should every progress update include?

Select all that apply, or skip this question.

When should work begin?

Choose when the agent should begin the work.

type Question = {
  name: string;
  required: boolean;
  prompt: string;
  description: string;
  choices: { value: string; label: string; description?: string }[];
  input?: { label: string; placeholder: string };
};

const items: Question[] = [
  {
    name: 'prototype',
    required: true,
    prompt: 'What should we prototype next?',
    description: 'Choose a direction or write your own.',
    choices: [
      { value: 'delegation', label: 'Delegation', description: 'Show how work moves to a specialist.' },
      { value: 'questions', label: 'Question prompts', description: 'Show choices while the interface waits.' },
      { value: 'both', label: 'Both together' },
    ],
    input: { label: 'Another answer', placeholder: 'Type another answer…' },
  },
  {
    name: 'detail',
    required: false,
    prompt: 'How much detail should it include?',
    description: 'Skip this if you are not sure yet.',
    choices: [
      { value: 'focused', label: 'Focused' },
      { value: 'complete', label: 'Complete flow' },
    ],
  },
];
html`
  <ui-questionnaire>
    <ui-questionnaire-progress></ui-questionnaire-progress>
    ${items.map((question) => html`
      <ui-questionnaire-item name=${question.name} ?required=${question.required}>
        <ui-questionnaire-title>${question.prompt}</ui-questionnaire-title>
        <ui-questionnaire-description>${question.description}</ui-questionnaire-description>
        <ui-questionnaire-choices>
          ${question.choices.map((choice) => html`
            <ui-questionnaire-choice value=${choice.value}>
              ${choice.label}
              ${choice.description
                ? html`<ui-questionnaire-choice-description>${choice.description}</ui-questionnaire-choice-description>`
                : ''}
            </ui-questionnaire-choice>
          `)}
          ${question.input
            ? html`<ui-questionnaire-input aria-label=${question.input.label} placeholder=${question.input.placeholder}></ui-questionnaire-input>`
            : ''}
        </ui-questionnaire-choices>
        <ui-questionnaire-error></ui-questionnaire-error>
      </ui-questionnaire-item>
    `)}
    <ui-questionnaire-actions>
      <ui-questionnaire-previous></ui-questionnaire-previous>
      <ui-questionnaire-skip></ui-questionnaire-skip>
      <ui-questionnaire-next></ui-questionnaire-next>
      <ui-questionnaire-submit></ui-questionnaire-submit>
    </ui-questionnaire-actions>
  </ui-questionnaire>
`
questionnaire.addEventListener('submit', (event) => {
  // The element cancels a submit that only moved to the next item.
  if (event.defaultPrevented) return;
  event.preventDefault();

  const formData = new FormData(event.target as HTMLFormElement);
  console.log({
    prototype: formData.get('prototype'),
    detail: formData.get('detail'),
  });
});

Every part renders on the server from its markup, and the element reads the item order from the DOM. Before the element loads, every item shows at once and Submit is the only action; once it loads it shows one item at a time and fills in the progress and the Previous, Skip and Next actions.

Multiple selection

multiple turns an item's fixed choices into native checkboxes. Read the answers with FormData.getAll().

What context should the agent inspect?

Select every source that may affect the implementation.

<ui-questionnaire-item name="signals" multiple required>
  <ui-questionnaire-title>What should every update include?</ui-questionnaire-title>
  <ui-questionnaire-description>Select all that apply.</ui-questionnaire-description>
  <ui-questionnaire-choices>
    <ui-questionnaire-choice value="progress">Progress</ui-questionnaire-choice>
    <ui-questionnaire-choice value="decisions">Decisions</ui-questionnaire-choice>
    <ui-questionnaire-choice value="risks">Risks</ui-questionnaire-choice>
  </ui-questionnaire-choices>
  <ui-questionnaire-error></ui-questionnaire-error>
</ui-questionnaire-item>
const signals = new FormData(form).getAll('signals').map(String);

Freeform answers

<ui-questionnaire-input> adds a freeform answer and renders a native text input named after its item. On a single-answer item, typing clears the picked choice and picking a choice clears the text.

How should the agent approach this refactor?

Choose a strategy or write a more specific instruction.

<ui-questionnaire-item name="prototype" required>
  <ui-questionnaire-title>What should we prototype next?</ui-questionnaire-title>
  <ui-questionnaire-choices>
    <ui-questionnaire-choice value="delegation">Delegation</ui-questionnaire-choice>
    <ui-questionnaire-choice value="questions">Question prompts</ui-questionnaire-choice>
    <ui-questionnaire-input
      aria-label="Another prototype direction"
      placeholder="Type another direction…"
    ></ui-questionnaire-input>
  </ui-questionnaire-choices>
  <ui-questionnaire-error></ui-questionnaire-error>
</ui-questionnaire-item>

The text input is always submitted, as an empty string when it was not used, so treat "" as no answer.

Explicit skip

<ui-questionnaire-skip> shows on an optional item, clears that item's answers, and moves on. A skipped item submits like an unanswered one, its choices absent from FormData and its text input empty. When your application needs to tell the two apart, record the click on the Skip action together with the active item, which the ui-active-change event names.

What kind of change is this?

Choose the category that best describes the work.

Are there any implementation constraints?

Answer if needed, or intentionally skip this question.

How should the work be reviewed?

Choose the checks the agent should complete before handoff.

let active = questionnaire.items()[0]?.name;
const skipped = new Set<string>();

questionnaire.addEventListener('ui-active-change', (e) => {
  active = e.detail.name;
});
questionnaire.querySelector('ui-questionnaire-skip')?.addEventListener('click', () => {
  skipped.add(active);
});
<ui-questionnaire>
  <ui-questionnaire-item name="timing">
    <ui-questionnaire-title>When should this be revisited?</ui-questionnaire-title>
    <ui-questionnaire-description>Skip this if timing has not been decided.</ui-questionnaire-description>
    <ui-questionnaire-choices>
      <ui-questionnaire-choice value="week">This week</ui-questionnaire-choice>
      <ui-questionnaire-choice value="cycle">Next cycle</ui-questionnaire-choice>
    </ui-questionnaire-choices>
  </ui-questionnaire-item>
  <ui-questionnaire-actions>
    <ui-questionnaire-skip></ui-questionnaire-skip>
    <ui-questionnaire-submit></ui-questionnaire-submit>
  </ui-questionnaire-actions>
</ui-questionnaire>

Answer shortcuts

Use shortcuts="letters" or shortcuts="numbers" to give each fixed choice a key, by its position in its item. Each choice shows its own hint.

What should the agent do next?

Use the displayed shortcut or navigate with the keyboard.

<ui-questionnaire shortcuts="letters">
  <ui-questionnaire-item name="review" required>
    <ui-questionnaire-title>What should the agent review?</ui-questionnaire-title>
    <ui-questionnaire-choices>
      <ui-questionnaire-choice value="api">Public API</ui-questionnaire-choice>
      <ui-questionnaire-choice value="tests">Test coverage</ui-questionnaire-choice>
    </ui-questionnaire-choices>
  </ui-questionnaire-item>
</ui-questionnaire>

"letters" assigns A through Z; "numbers" assigns 1 through 9. A disabled choice keeps its position, so the keys after it do not shift, and its own key does nothing. Selecting an answer by shortcut does not advance to the next item. Set the attribute in the markup, since the choices read it when they render.

Validation

Questionnaire validates the active item before moving forward, and when the form submits on the last item it returns to the first required item that has no answer.

  • A required item is valid after it has an answer: a checked choice or a filled text input.
  • An optional item is always valid.
  • Disabled items are left out.

required does not add visible "Required" text. Say it in the title or description.

When validation fails, Questionnaire keeps or opens the invalid item, marks its fieldset aria-invalid, and focuses its first answer. Add <ui-questionnaire-error> to show a message.

<ui-questionnaire-item name="scope" required>
  <ui-questionnaire-title>What should the project include? (Required)</ui-questionnaire-title>
  <ui-questionnaire-choices><!-- choices --></ui-questionnaire-choices>
  <ui-questionnaire-error></ui-questionnaire-error>
</ui-questionnaire-item>

The error stays hidden until the item is invalid. Its content replaces the default message, which is "Choose an answer to continue." on a required item.

<ui-questionnaire-error>Please choose a project scope.</ui-questionnaire-error>

Validation still works without an error part. When one is rendered, it is a role="alert" while shown, so the message is announced.

For Zod or another validator, check the FormData in a submit listener, cancel the submit when it fails, and set the item's invalid property, which shows its error on the item on screen, the last one when Submit fires.

How much detail should the answer include?

Choose the response depth.

Who will read the answer?

Public answers require complete context.

import type { UiQuestionnaireItem } from '#components/ui/questionnaire.ts';

questionnaire.addEventListener('submit', (event) => {
  if (event.defaultPrevented) return;
  const data = Object.fromEntries(new FormData(event.target as HTMLFormElement));
  if (!schema.safeParse(data).success) {
    event.preventDefault();
    const item = questionnaire.querySelector<UiQuestionnaireItem>('ui-questionnaire-item[name="audience"]');
    if (item) item.invalid = true;
  }
});

Controlled navigation

The element owns the active item. It dispatches ui-active-change with { detail: { name } } each time it moves, so your state can follow it, and its next(), previous() and skip() methods move it from your own controls.

Current checkpoint: Change scope

What may the agent change?

The host stores the active checkpoint while Questionnaire navigates.

Which verification level should it use?
What should the agent return when finished?
questionnaire.addEventListener('ui-active-change', (e) => {
  status.textContent = `Current checkpoint: ${e.detail.name}`;
});

nextButton.addEventListener('click', () => questionnaire.next());

Resume with defaults

Restore a saved draft with checked on the choices. The flow starts on the first item.

What kind of migration is this?

This answer was saved during the previous session.

How should the migration be verified?

These checks were selected during the previous session.

Anything else the agent should remember?

This note was saved with the draft.

<ui-questionnaire>
  <ui-questionnaire-item name="scope" required>
    <ui-questionnaire-title>Which files are in scope?</ui-questionnaire-title>
    <ui-questionnaire-choices>
      <ui-questionnaire-choice value="component" checked>Component only</ui-questionnaire-choice>
    </ui-questionnaire-choices>
  </ui-questionnaire-item>
</ui-questionnaire>

Conditional items

Set disabled to remove an item from the current flow. Disabled items are excluded from progress, navigation, validation, and submission. To change it at runtime, toggle the attribute from a change listener and call the questionnaire's sync().

Where should the agent run?

Cloud runs add an environment question to this flow.

Which cloud environment should it use?
When should the agent request approval?
questionnaire.addEventListener('change', (e) => {
  const input = e.target as HTMLInputElement;
  if (input.name !== 'runtime') return;
  questionnaire
    .querySelector('ui-questionnaire-item[name="region"]')
    ?.toggleAttribute('disabled', input.value !== 'remote');
  questionnaire.sync();
});

Navigation actions stay enabled so activating Next or Submit can show a validation error. To change the look of Next while the active item has no checked choice, select on the state the markup does carry:

What may the agent modify?

Next stays on this question until an answer is selected.

What must pass before completion?
[data-slot="questionnaire"]:not(:has([data-slot="questionnaire-item"][data-active] :checked))
  [data-slot="questionnaire-next"] {
  opacity: 0.5;
}

Custom progress

<ui-questionnaire-progress> renders Question {current} of {total} and takes no render target or content. Style it with classes. For another format, render your own line and update it from ui-active-change.

How large is the change?
How should commits be organized?
Which tests should run?
How should the work be delivered?
questionnaire.addEventListener('ui-active-change', (e) => {
  const items = questionnaire.items();
  const current = items.findIndex((item) => item.name === e.detail.name) + 1;
  output.textContent = `Checkpoint ${current} of ${items.length}`;
});

The progressbar's accessible name is fixed as "Questionnaire progress"; an aria-label on the element is not passed to it.

Animated items

Animate the active item while keeping progress and navigation stationary. A class on <ui-questionnaire-item> lands on the fieldset it renders, which carries data-active while it is shown.

What should the agent do?

Choose the task for this run.

How should the work be reviewed?

Select the verification depth.

How should the result be delivered?

Choose the final handoff format.

<ui-questionnaire-item
  class="data-active:animate-in data-active:fade-in-0 data-active:slide-in-from-bottom-2 data-active:duration-300 motion-reduce:animate-none"
  name="task"
  required
>
  ...
</ui-questionnaire-item>

Inactive items hide immediately, so animate the entry only.

Card composition

Place the root around a card and put the title and description in the card header, with the card's classes on them. The title still renders the legend, and the item names its fieldset by the title wherever it sits.

What should the agent work on?

Choose the task that should be handled next.

What should the final handoff include?

Pick the level of detail needed for review.

<ui-questionnaire>
  <div data-slot="card" class=${cardClass()}>
    <ui-questionnaire-item name="task" required>
      <div data-slot="card-header" class=${cardHeaderClass()}>
        <ui-questionnaire-title class=${cardTitleClass()}>What should the agent work on?</ui-questionnaire-title>
        <ui-questionnaire-description class=${cardDescriptionClass()}>
          Choose the task that should be handled next.
        </ui-questionnaire-description>
        <div data-slot="card-action" class=${cardActionClass()}>
          <ui-questionnaire-progress></ui-questionnaire-progress>
        </div>
      </div>
      <div data-slot="card-content" class=${cardContentClass()}>
        <ui-questionnaire-choices><!-- choices --></ui-questionnaire-choices>
        <ui-questionnaire-error></ui-questionnaire-error>
      </div>
    </ui-questionnaire-item>
    <div data-slot="card-footer" class=${cardFooterClass()}>
      <ui-questionnaire-next>Next</ui-questionnaire-next>
      <ui-questionnaire-submit>Submit</ui-questionnaire-submit>
    </div>
  </div>
</ui-questionnaire>

Dialog composition

Keep dialog dismissal separate from Skip: closing cancels the flow, while skipping records an intentional unanswered item.

Which files are in scope?

Choose how broadly the agent can update the workspace.

How much verification is needed?

Choose the checks the agent should run before handoff.

<ui-dialog>
  <ui-dialog-trigger><button class=${buttonClass({ variant: 'outline' })}>Open clarification</button></ui-dialog-trigger>
  <ui-dialog-content>
    <ui-questionnaire>
      <ui-questionnaire-item name="scope" required>
        <div data-slot="dialog-header" class=${dialogHeaderClass()}>
          <ui-questionnaire-progress></ui-questionnaire-progress>
          <ui-questionnaire-title class=${dialogTitleClass()}>Which files are in scope?</ui-questionnaire-title>
          <ui-questionnaire-description class=${dialogDescriptionClass()}>
            Choose how broadly the agent can update the workspace.
          </ui-questionnaire-description>
        </div>
        <ui-questionnaire-choices><!-- choices --></ui-questionnaire-choices>
        <ui-questionnaire-error></ui-questionnaire-error>
      </ui-questionnaire-item>
      <div data-slot="dialog-footer" class=${dialogFooterClass()}>
        <ui-dialog-close><button class=${buttonClass({ variant: 'outline' })}>Cancel</button></ui-dialog-close>
        <ui-questionnaire-next>Next</ui-questionnaire-next>
        <ui-questionnaire-submit>Send answer</ui-questionnaire-submit>
      </div>
    </ui-questionnaire>
  </ui-dialog-content>
</ui-dialog>

Custom render targets

Each part renders a fixed element (the root a form, an item a fieldset, a title a legend, a description a p, the actions buttons), and a class on the part is merged onto that element. A part's host is display: contents, so the rendered element is the box its parent lays out. To render something else, edit the component file the CLI copied into your project.

Unlike the headless primitive, every rendered element carries a data-slot, which the styles key on and you can select on too.

Native forms

<ui-questionnaire> always renders a native form. It takes action and method attributes, which it passes to the form, and the native submit and reset events bubble from it. Do not nest a questionnaire inside another form. Binding a 'use server' action needs action=${fn} on a <form> your template writes, so the element's form takes a URL, not a server action.

Answers serialize through native controls:

  • FormData.get(itemName) reads a single answer.
  • FormData.getAll(itemName) reads multiple answers.
  • A skipped item's choices are absent from FormData; its text input, if it has one, is present and empty.

The form gets novalidate once the element loads, so validation uses the error parts instead of the browser's constraint UI. With JavaScript off every item shows, and the browser's own required check covers a required single-answer item's radios.

form.reset() restores the native controls only. The element does not reset the active item or the validation state.

Keyboard navigation

Questionnaire builds on native radio, checkbox, input, and button behavior.

KeyBehavior
TabMoves focus between answer controls and visible actions. Inactive items are inert and hidden actions are hidden, so neither takes focus.
Shift + TabMoves focus to the previous control or action.
ArrowUp, ArrowDown, ArrowLeft, ArrowRightNative radio behavior: moves to and selects the previous or next radio of the active item. Arrow keys do not move between items.
SpaceSelects a radio, toggles a checkbox, or activates a focused action.
EnterIn an answer control, submits the form the browser's way, which the element turns into Next, validating first, and on the last item into Submit. On a focused action, activates it.
A to Z, 1 to 9With shortcuts, selects the matching choice of the active item, or toggles it in a multiple item. Does not advance.

Shortcuts pause while you type in a text field and while Ctrl, Cmd or Alt is held. Enter is the browser's own form submission. Leave out shortcuts to keep the keys free.

Navigation actions stay enabled so an attempted action can reveal validation feedback. See Navigation state to restyle an unanswered action.

Accessibility

  • <ui-questionnaire-item> renders a fieldset.
  • <ui-questionnaire-title> renders a legend with an id, and the item names its fieldset by it with aria-labelledby, wherever the title sits inside the item.
  • The description and, while the item is invalid, the error are connected with aria-describedby.
  • An invalid item's fieldset exposes aria-invalid="true", and its error is a role="alert". The answer controls do not carry aria-invalid.
  • <ui-questionnaire-progress> renders a role="progressbar" named "Questionnaire progress", with current, minimum, maximum, and text values, as a polite live region.
  • Fixed choices are native radios and checkboxes.
  • Assigned shortcut keys are exposed with aria-keyshortcuts on each choice's input, and the visible Next or Submit carries aria-keyshortcuts="Enter".
  • Inactive items are hidden and inert; actions that do not apply are hidden and aria-hidden.
  • Navigation focuses the newly active item's first available answer.
  • Validation focuses the first available answer control.
  • Disabled items are omitted from progress and navigation.

Always give <ui-questionnaire-input> an accessible name with aria-label, which the element passes to the input it renders. When the input has a visible label, repeat its text in aria-label.

<ui-questionnaire-input
  aria-label="Other answer"
  placeholder="Type another answer…"
></ui-questionnaire-input>

A placeholder is not a label.

Data attributes

Use these attributes for styling. Boolean attributes are present when true and absent when false. They sit on the elements the parts render, not on the part hosts, and every rendered element also carries a data-slot named after its part. Some states are carried by a native or ARIA attribute, which is listed with them.

Root and Progress

Data attributeValue
data-shortcuts"letters" | "numbers" on the form when enabled.

The progress element carries the position as aria-valuenow and aria-valuemax.

Item

Data attributeValue
data-activePresent on the active item's fieldset once the element has loaded.

The fieldset also carries hidden and inert while inactive, disabled when the item is disabled, and aria-invalid="true" after failed validation.

Choice

Data attributeValue
data-type"radio" | "checkbox"
data-checkedPresent when selected.
data-uncheckedPresent when not selected.
data-disabledPresent when the choice or its item is disabled.
data-shortcutThe assigned key, a lowercase letter or a number. The hint shows it in uppercase.

The choice renders a label (data-slot="questionnaire-choice") holding the input (questionnaire-choice-input), the indicator (questionnaire-choice-indicator, with -indicator-dot and -indicator-check), the label text (questionnaire-choice-label) and the shortcut hint (questionnaire-choice-shortcut).

Choices

No state attributes. The shortcut mode is on the form's data-shortcuts.

Input

No state attributes. The input (data-slot="questionnaire-input") sits in a wrapper (questionnaire-input-wrapper) and is natively disabled with its item; style an empty input with :placeholder-shown.

Error

No state attributes. The error is hidden until its item is invalid, and a role="alert" while it shows.

Previous, Skip, Next, and Submit

Data attributeValue
data-variantThe button variant.
data-sizeThe button size.

An action that does not apply to the active item is hidden and aria-hidden; a visible Next or Submit carries aria-keyshortcuts="Enter".

API Reference

ui-questionnaire

The form and coordination root.

AttributeTypeDefaultDescription
shortcuts"letters" | "numbers"-Assigns answer shortcuts by each choice's position in its item.
actionstring-The form's action URL, used when the last item submits.
methodstring-The form's method.
classstring-Merged onto the form.
Method or eventDescription
next()Validates the active item and moves to the next one.
previous()Moves back one item.
skip()Clears an optional active item's answers and moves on.
validate(item?)Checks an item, the active one by default. Marks it invalid, focuses its answer and returns false when it needs an answer.
answered(item)Whether an item has a checked choice or a filled text input.
items()The items in the flow, in order: every one not disabled.
sync()Redraws the parts after your code changes an item, such as its disabled attribute.
ui-active-changeDispatched (bubbling) after the active item changes, with { detail: { name } }.
submitThe native submit event. The element cancels a submit that only moved to the next item, so check defaultPrevented.

The flow starts on the first enabled item, the order comes from the markup, and novalidate is set once the element loads.

ui-questionnaire-progress

Position within the enabled items. It renders Question {current} of {total} and takes no attributes, content or render target apart from a merged class. Its accessible name is "Questionnaire progress".

ui-questionnaire-item

One questionnaire step, rendered as a fieldset.

AttributeTypeDefaultDescription
namestring""Unique item identifier and the native form field name of its answers.
requiredbooleanfalseRequires an answer and hides Skip.
multiplebooleanfalseRenders fixed choices as checkboxes.
disabledbooleanfalseOmits the item from progress, navigation, validation and submission.

It also has an invalid property, set by validation and settable from your own validator, and inputs() and choices() methods returning its answer controls and its choices. Item names must be unique within a questionnaire.

ui-questionnaire-title

The item title. It renders a legend with an id the item uses for aria-labelledby, and takes a merged class.

ui-questionnaire-description

Supporting text, rendered as a p and connected to the item with aria-describedby. It takes a merged class.

ui-questionnaire-choices

A layout container (a div) for fixed and freeform answers. It takes a merged class.

ui-questionnaire-choice

A fixed answer. It renders a label around a native radio, or a checkbox in a multiple item, its indicator, its content and its shortcut hint, so the whole row is associated with the control.

AttributeTypeDefaultDescription
valuestring""Native answer value.
checkedbooleanfalseInitial checked state.
disabledbooleanfalseDisables the native answer control.
classstring-Merged onto the label.

Its input() method returns the native control, which owns its state after the first render. Put a <ui-questionnaire-choice-description> inside for a second line.

Choice input, label and shortcut

The choice's input, label and shortcut hint are rendered by <ui-questionnaire-choice>: the input is laid transparent over the row, the label text is the choice's content, and the shortcut hint shows the assigned key and stays hidden without one. They are not separate elements, so they take no attributes; style them through their data-slot.

ui-questionnaire-input

A freeform answer, a native text input whose name is its item's.

AttributeTypeDefaultDescription
placeholderstring""The input's placeholder.
aria-labelstring-The input's accessible name.
classstring-Merged onto the wrapper around the input.

The input is a type="text" field.

ui-questionnaire-error

The validation message, a p hidden until its item fails validation. Its content replaces the default message, "Choose an answer to continue." on a required item and "Choose an answer or skip this question." otherwise. It takes a merged class.

<ui-questionnaire-previous>, <ui-questionnaire-skip>, <ui-questionnaire-next> and <ui-questionnaire-submit> render native buttons and stay mounted while their visibility changes. Their content replaces the default label.

PartTypeVisible whenDisabled when
<ui-questionnaire-previous>"button"Not on the first item.Never.
<ui-questionnaire-skip>"button"The active item is optional.Never.
<ui-questionnaire-next>"button"Not on the last item.Never.
<ui-questionnaire-submit>"submit"On the last item, and before the element loads.Never.
AttributeTypeDefault
varianta Button variant"outline", "default" on Next and Submit
sizea Button size"default"
classstringMerged onto the button.

<ui-questionnaire-actions> is the layout container: a grid that places Previous at the start and Skip, Next and Submit at the end. It takes a merged class.