Skip to content
Haze UI

Questionnaire

A form that asks one question at a time, with choice and text questions, optional Skip, script validation, Back and a progress bar.

pnpm dlx shadcn@latest add @haze/questionnaire
Open preview in a new tab
Livesmall script

When to use

  • An AI agent or setup flow asks a few clarifying questions and each deserves the reader's full attention
  • An intake form mixes single choice, multiple choice and free text, and some questions can be skipped
  • A short survey must still submit as one plain form, with native checks on required text and single choice, if scripts fail

When not to use

  • Questions are unrelated fields of one record, such as an address. Use fieldset with form fields.
  • The steps are a long flow with its own screens and a numbered header. Use stepper.
  • The flow must stay inside a modal. Use dialog-stack.

Installation

Add the Haze registry to components.json once, then install Questionnaire with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.

pnpm dlx shadcn@latest add @haze/questionnaire
First time? Registry and theme setup

1. Add to components.json:

{
  "registries": {
    "@haze": "http://localhost:4329/r/{name}.json"
  }
}

2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";

API reference

PropTypeDefaultDescription
id*string–Id of the form; question and message ids derive from it.
questions{ id: string; title: string; description?: string; type: "single" | "multiple" | "text"; options?: { value: string; label: string; description?: string }[]; required?: boolean; placeholder?: string }[]four-question workspace intakeQuestions in order. The question id is the form field name. Questions are optional unless required is true.
actionstring"#workspace-setup"Where the form posts.
method"get" | "post" | "dialog""post"Form method.
headingLevel2 | 3 | 4 | 5 | 63Heading level of each question title.
questionLabelstring"Question"First word of the counter, "Question 2 of 4".
ofLabelstring"of"Middle word of the counter.
progressLabelstring"Progress"Accessible name of the progress bar.
optionalLabelstring"optional"Marker after the title of an optional question.
backLabelstring"Back"Back button text.
nextLabelstring"Next"Next button text.
skipLabelstring"Skip"Skip button text, shown on optional questions.
submitLabelstring"Submit"Submit button text.
errorLabels{ single: string; multiple: string; text: string }English messagesMessage shown when a required question is empty, by question type.
classstring–Extra classes on the form.

Keyboard interactions

TabShiftTab
Move between the answers and the buttons.
Arrow keys
Change the selected option in a single-choice question.
Space
Toggle a checkbox option.
Enter
Go to the next question from a choice; press Submit on the last one.

Accessibility

  • Every question is a fieldset with its title in the legend, so choices are announced with their question.
  • A blocked Next shows the message under the question, adds it to each control's aria-describedby while it shows, marks the controls invalid and moves focus to the first one.
  • Moving between questions puts focus on the new question's heading. The counter is plain text with a matching progress bar.
  • Enter in a field moves to the next question instead of submitting early; in the text area it adds a line.
  • Without script all questions show in one form with one Submit button and the browser's own validation: required text and required single-choice questions are enforced. HTML has no native "at least one" rule for checkboxes, so a required multiple-choice question is enforced only with script.

Notes for AI

Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.

  • Install and use

    Install the Haze UI component "Questionnaire" with `npx shadcn@latest add @haze/questionnaire`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import Questionnaire from "@/components/haze/ui/questionnaire.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/questionnaire.md

  • Customize with real content

    Adapt the Haze questionnaire ui for our product. Replace the demo values of these props with our real content: id, questions, action, method, headingLevel, questionLabel, ofLabel, progressLabel, optionalLabel, backLabel, nextLabel, skipLabel, submitLabel, errorLabels, class. Keep the layout, the heading level rules and these accessibility details: Every question is a fieldset with its title in the legend, so choices are announced with their question. A blocked Next shows the message under the question, adds it to each control's aria-describedby while it shows, marks the controls invalid and moves focus to the first one. Moving between questions puts focus on the new question's heading. The counter is plain text with a matching progress bar. Enter in a field moves to the next question instead of submitting early; in the text area it adds a line. Without script all questions show in one form with one Submit button and the browser's own validation: required text and required single-choice questions are enforced. HTML has no native "at least one" rule for checkboxes, so a required multiple-choice question is enforced only with script. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using questionnaire, check it fits: use it when an ai agent or setup flow asks a few clarifying questions and each deserves the reader's full attention; an intake form mixes single choice, multiple choice and free text, and some questions can be skipped; a short survey must still submit as one plain form, with native checks on required text and single choice, if scripts fail. Avoid it when questions are unrelated fields of one record, such as an address. use fieldset with form fields.; the steps are a long flow with its own screens and a numbered header. use stepper.; the flow must stay inside a modal. use dialog-stack.. Alternatives: @haze/stepper, @haze/dialog-stack, @haze/fieldset, @haze/radio-group.

Dependencies

  • npm: @lucide/astro
  • @haze/button
  • @haze/checkbox
  • @haze/textarea
  • @haze/utils
  • @haze/theme (one-time setup)

Source · Original Haze UI work.

Catalog

↑↓ moveEnter openEsc close

Keyboard shortcuts

CtrlK
Command palette
/
Focus search
←↑→↓
Move between cards
jk
Next / previous card
ci
Copy code / install command (detail page)
[]
Previous / next entry
?
This help
Esc
Close dialog