Components
Quiz
Questions that show right and wrong answers.
Which element should you use for a clickable action?
<Quiz questions={questions} />Installation
npx shadcn@latest add https://ui.zjkm.tech/r/quiz.jsonimport { Quiz } from "@/components/quiz"Using JavaScript? Set tsx: false in components.json and the CLI converts it.
New to shadcn? Run npx shadcn@latest init first. The CLI needs components.json and the @/ import alias.
Usage
Questions that show right and wrong straight away, with an explanation, then a score at the end. The feedback is announced to screen readers, and focus moves to each new question.
import { Quiz } from "@/components/quiz";
const questions = [
{ question: "Which element is best for a button?", options: ["<div>", "<button>", "<span>"], answer: 1, explain: "It's focusable and works with Enter and Space." },
];
export function A11yQuiz() {
return <Quiz questions={questions} />;
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
questions | { question, options, answer, explain? }[] | The questions. answer is the right option's index. | |
className | string | Classes for the wrapper. |
With reduced motion, answers don't pop or shake.