Skip to Content
zjkm-ui
Components

Quiz

Questions that show right and wrong answers.

Question 1 of 3Score 0

Which element should you use for a clickable action?

Props
<Quiz questions={questions} />

Installation

npx shadcn@latest add https://ui.zjkm.tech/r/quiz.json
import { 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

PropTypeDefaultDescription
questions{ question, options, answer, explain? }[]The questions. answer is the right option's index.
classNamestringClasses for the wrapper.

With reduced motion, answers don't pop or shake.

On this page