Skip to content
VinUIComponentsQuestionnaire

Questionnaire

Multiple-choice questions the assistant asks inside a chat: one answer (radios) or several (checkboxes), an optional "Other" text box, Submit and Skip, and a read-only view once answered. Same markup and props in every style: switch the style in the header to see it change.

Basic

One question with an "Other" text box that shows when you choose it. In HTML, add data-vin-questionnaire to the form.

How long do you want to hike?
questionnaire-basic.html
<form class="vin-questionnaire" data-vin-questionnaire aria-label="Trip length" style="max-width: 440px">
  <fieldset class="vin-questionnaire__question">
    <legend class="vin-questionnaire__prompt">How long do you want to hike?</legend>
    <div class="vin-choice">
      <input type="radio" class="vin-radio" id="qb-len-0" name="qb-len" value="short">
      <div class="vin-choice__body"><label class="vin-choice__label" for="qb-len-0">Under 2 hours</label></div>
    </div>
    <div class="vin-choice">
      <input type="radio" class="vin-radio" id="qb-len-1" name="qb-len" value="half-day">
      <div class="vin-choice__body"><label class="vin-choice__label" for="qb-len-1">Half a day</label></div>
    </div>
    <div class="vin-choice">
      <input type="radio" class="vin-radio" id="qb-len-2" name="qb-len" value="full-day">
      <div class="vin-choice__body"><label class="vin-choice__label" for="qb-len-2">A full day</label></div>
    </div>
    <div class="vin-choice">
      <input type="radio" class="vin-radio" id="qb-len-other" name="qb-len" value="other">
      <div class="vin-choice__body">
        <label class="vin-choice__label" for="qb-len-other">Other</label>
        <input type="text" class="vin-input vin-input--sm vin-questionnaire__other" name="qb-len-other" aria-label="Other answer">
      </div>
    </div>
  </fieldset>
  <div class="vin-questionnaire__actions">
    <button type="button" class="vin-btn vin-btn--ghost vin-btn--sm" data-vin-skip>Skip</button>
    <button type="submit" class="vin-btn vin-btn--sm">Submit</button>
  </div>
</form>

Several questions

A title, a single-choice question and a choose-any question with Other filled in.

A few questions first

So I can plan the right trip for you.

Who is coming?
What would you like to see?

Choose any.

questionnaire-multiple.html
<form class="vin-questionnaire" data-vin-questionnaire aria-labelledby="qm-title" style="max-width: 440px">
  <div class="vin-questionnaire__header">
    <p class="vin-questionnaire__title" id="qm-title">A few questions first</p>
    <p class="vin-questionnaire__description">So I can plan the right trip for you.</p>
  </div>
  <fieldset class="vin-questionnaire__question">
    <legend class="vin-questionnaire__prompt">Who is coming?</legend>
    <div class="vin-choice">
      <input type="radio" class="vin-radio" id="qm-who-0" name="qm-who" value="solo" checked>
      <div class="vin-choice__body"><label class="vin-choice__label" for="qm-who-0">Just me</label></div>
    </div>
    <div class="vin-choice">
      <input type="radio" class="vin-radio" id="qm-who-1" name="qm-who" value="friends">
      <div class="vin-choice__body"><label class="vin-choice__label" for="qm-who-1">Friends</label></div>
    </div>
    <div class="vin-choice">
      <input type="radio" class="vin-radio" id="qm-who-2" name="qm-who" value="kids">
      <div class="vin-choice__body"><label class="vin-choice__label" for="qm-who-2">Family with kids</label></div>
    </div>
  </fieldset>
  <fieldset class="vin-questionnaire__question">
    <legend class="vin-questionnaire__prompt">What would you like to see?</legend>
    <p class="vin-questionnaire__hint">Choose any.</p>
    <div class="vin-choice">
      <input type="checkbox" class="vin-checkbox" id="qm-see-0" name="qm-see" value="lakes" checked>
      <div class="vin-choice__body"><label class="vin-choice__label" for="qm-see-0">Lakes</label></div>
    </div>
    <div class="vin-choice">
      <input type="checkbox" class="vin-checkbox" id="qm-see-1" name="qm-see" value="views">
      <div class="vin-choice__body"><label class="vin-choice__label" for="qm-see-1">Mountain views</label></div>
    </div>
    <div class="vin-choice">
      <input type="checkbox" class="vin-checkbox" id="qm-see-2" name="qm-see" value="waterfalls">
      <div class="vin-choice__body"><label class="vin-choice__label" for="qm-see-2">Waterfalls</label></div>
    </div>
    <div class="vin-choice">
      <input type="checkbox" class="vin-checkbox" id="qm-see-other" name="qm-see" value="other" checked>
      <div class="vin-choice__body">
        <label class="vin-choice__label" for="qm-see-other">Other</label>
        <input type="text" class="vin-input vin-input--sm vin-questionnaire__other" name="qm-see-other" value="Wildflowers" aria-label="Other answer">
      </div>
    </div>
  </fieldset>
  <div class="vin-questionnaire__actions">
    <button type="button" class="vin-btn vin-btn--ghost vin-btn--sm" data-vin-skip>Skip</button>
    <button type="submit" class="vin-btn vin-btn--sm">Submit</button>
  </div>
</form>

Answered

Read-only after Submit: only the chosen answer stays, with a note that it was sent.

How long do you want to hike?

Answer sent

questionnaire-submitted.html
<form class="vin-questionnaire" data-state="submitted" aria-label="Trip length" style="max-width: 440px">
  <fieldset class="vin-questionnaire__question" disabled>
    <legend class="vin-questionnaire__prompt">How long do you want to hike?</legend>
    <div class="vin-choice">
      <input type="radio" class="vin-radio" id="qs-len-0" name="qs-len" value="short">
      <div class="vin-choice__body"><label class="vin-choice__label" for="qs-len-0">Under 2 hours</label></div>
    </div>
    <div class="vin-choice">
      <input type="radio" class="vin-radio" id="qs-len-1" name="qs-len" value="half-day" checked>
      <div class="vin-choice__body"><label class="vin-choice__label" for="qs-len-1">Half a day</label></div>
    </div>
    <div class="vin-choice">
      <input type="radio" class="vin-radio" id="qs-len-2" name="qs-len" value="full-day">
      <div class="vin-choice__body"><label class="vin-choice__label" for="qs-len-2">A full day</label></div>
    </div>
  </fieldset>
  <p class="vin-questionnaire__status" role="status"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="m8.5 12 2.5 2.5 4.5-5"/></svg>Answer sent</p>
</form>

Installation

React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:

Terminal
npx @vinish/ui add questionnaire
React
import { Questionnaire } from "@/components/vin/questionnaire";
Vue
import Questionnaire from "@/components/vin/questionnaire.vue";
Svelte
import Questionnaire from "$lib/components/vin/questionnaire.svelte";

The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.

Plain HTML: the classes come with the style's stylesheet. This component also needs vinui.js for its keyboard and pointer behaviour.

API

From spec/questionnaire.json, which every framework version is tested against.

PropValuesDefaultIn HTML
questions
{ id, prompt, hint?, multiple?, options: (string | { value, label })[], other?: boolean | string }. multiple uses checkboxes; other adds an "Other" option with a text box.
Question[]—fieldset.vin-questionnaire__question > legend.vin-questionnaire__prompt + .vin-choice (Radio or Checkbox) ...
title / description
A heading above the questions; it names the form.
ReactNode—.vin-questionnaire__header > .vin-questionnaire__title + .vin-questionnaire__description
label
Name for the form when there's no title.
string—aria-label on the form
defaultValues / defaultOther
Chosen values ("other" for the Other option) and the typed Other text, by question id.
Record<string, string[]> / Record<string, string>——
onSubmit
Answers by question id: a string, or a list for multiple. Other gives the typed text.
(answers) => void—vinui.js fires vin-submit with detail.answers, keyed by each question's input name (add data-vin-questionnaire to the form)
onSkip() => void—button[data-vin-skip]; vinui.js fires vin-skip
state / defaultState
After Submit only the chosen answers stay, read-only; after Skip the questions fold away.
opensubmittedskippedopendata-state on the form, fieldsets disabled, p.vin-questionnaire__status[role=status]
submitLabel / skipLabel
skipLabel={null} hides Skip.
stringSubmit / Skip—
submittedText / skippedTextReactNodeAnswers sent / Skipped—

Parts

React, Vue, SvelteHTML classes
<Questionnaire>.vin-questionnaire.vin-questionnaire__header.vin-questionnaire__title.vin-questionnaire__description.vin-questionnaire__question.vin-questionnaire__prompt.vin-questionnaire__hint.vin-questionnaire__other.vin-questionnaire__actions.vin-questionnaire__status

Accessibility

  • Each question is a fieldset with its prompt as the legend, so screen readers read the question with every option.
  • Options are real radios and checkboxes: arrow keys move between radios, Space toggles checkboxes, and they work in forms without JavaScript.
  • The "Other" text box has its own label and only appears once Other is chosen.
  • After Submit or Skip, focus moves to the status line (role="status"), which says what happened; the answered questions stay readable but disabled.