PatternAvailable
Questionnaire
A small single-choice questionnaire with required-answer validation.
Installation
Add the component and its dependencies from the registry running on your computer.
terminal
npx shadcn@latest add https://brutallab.facilito.dev/r/questionnaire.jsonUsage
Import the component into your project and keep the source code under your control.
tsx
'use client';
import { useState } from 'react';
import { Questionnaire } from '@/components/ui/questionnaire';
export default function Demo() {
const [complete, setComplete] = useState(false);
return (
<div className="grid w-full max-w-lg gap-5">
<Questionnaire
questions={[
{
id: 'experience',
title: 'How often do you build interfaces?',
options: [
{ value: 'weekly', label: 'Every week' },
{ value: 'monthly', label: 'A few times a month' },
],
},
{
id: 'focus',
title: 'What would you like to practice?',
options: [
{ value: 'forms', label: 'Forms' },
{ value: 'navigation', label: 'Navigation' },
],
},
]}
onComplete={() => setComplete(true)}
/>
<output>
{complete
? 'Thanks. Your demo answers were accepted locally.'
: 'Choose one answer per question.'}
</output>
</div>
);
}
States & interaction
Appearance, behavior and keyboard checks.
- The composition inherits its controls’ states. Test empty, content, loading and error cases where the application needs them.
- Examples on this page are runnable; the displayed code uses the same components. Business logic belongs to the consumer.
- Test the example with Tab and Shift+Tab. Focus must stay visible in both themes.
API Reference
BrutalLab-specific properties. Native attributes are supported as well.
| Prop | Type | Default | Description |
|---|---|---|---|
| questions | Question[] | — | Questions with stable IDs and option values. |
| onComplete | (answers) => void | — | Called only after every question is answered. |
| submitLabel | string | Submit answers | Text of the submit action. |
Accessibility
Rules that should remain intact when adapting the component to a product.
Give each question a legend and every choice a visible label. Completion is a callback, not automatic persistence.
Retain keyboard focus styles and test the composition with keyboard navigation.
Use className for visual customization; preserve the primitive ARIA attributes.