TBX Docs
ExercisesCatalogue

YesNo

True/False or Yes/No questions

YesNo presents a list of statements with Yes/No (or custom labels) buttons. Ideal for fact-checking and true/false exercises.

Import

import { YesNo } from '@bside-tech/tbx-ui/components';

Example

Answer all questions below using a simple Yes or No.
Select true or false for each statement.
  • The Earth is flat.
    Answer for: The Earth is flat.
  • Water boils at 100°C at sea level.
    Answer for: Water boils at 100°C at sea level.
  • JavaScript and Java are the same language.
    Answer for: JavaScript and Java are the same language.
<YesNo
  entries={[
    { text: "The Earth is flat.", answer: false },
    { text: "Water boils at 100°C at sea level.", answer: true },
    { text: "JavaScript and Java are the same language.", answer: false },
  ]}
/>

With images

text can be any React node, so you can mix text and images in a statement. When text isn't a string, give the entry a name: it is used as the accessible label of that entry's Yes/No buttons.

Is the shape described correctly?
Select true or false for each statement.
  • This is a blue circle.
    Answer for: Blue circle
  • This is a red square.
    Answer for: Green square
  • This shape has three sides.
    Answer for: Orange triangle
import catImg from "../../_img/cat.png";
import dogImg from "../../_img/dog.png";

<YesNo
  title="Is the animal named correctly?"
  entries={[
    {
      name: "Cat",
      text: (
        <span className="inline-flex items-center gap-2">
          <img src={catImg} alt="" className="h-12 w-12 object-contain" />
          This is a cat.
        </span>
      ),
      answer: true,
    },
    {
      name: "Dog",
      text: (
        <span className="inline-flex items-center gap-2">
          <img src={dogImg} alt="" className="h-12 w-12 object-contain" />
          This is a horse.
        </span>
      ),
      answer: false,
    },
    // Strings and React nodes can be mixed in the same list:
    { text: "Cats and dogs are *mammals*.", answer: true },
  ]}
/>

Props

Prop

Type

Labels

Override labels via the labels prop. Supported keys: true, false (Yes/No buttons), check, reset (action buttons), results (e.g. "correct" in "3 / 5 correct"). Default for buttons: { true: "Yes", false: "No" }.

<YesNo
  entries={[
    { text: "The sky is blue.", answer: true },
    { text: "2 + 2 = 5.", answer: false },
  ]}
  labels={{
    true: "Agree",
    false: "Disagree",
    check: "Verify",
    reset: "Retry",
    results: "correct",
  }}
/>

Style

Tailwind v4 is available for all customisations. Pass classes via the classNames prop, or override CSS variables for fine-grained control.

CSS Classes

KeyElement
rootRoot wrapper
listQuestion list (ul)
itemEach question row (li)
textStatement text
buttonsYes/No button group
buttonEach option button
checkButtonCheck button
resetButtonReset button
resultResults text

CSS Variables

Scoped under .tbx-yesno:

VariablePurpose
--yesno-icon-colorIcon color (inherits --exercise-layout-icon-color)
--yesno-option-bgOption button background (default)
--yesno-option-bg-selectedOption button background when selected (before validation). Uses color-mix with --exercise-accent-color.
--yesno-option-border-selectedOption button border when selected (before validation). Uses --exercise-accent-color.
--yesno-item-borderRow divider
--yesno-action-bg, --yesno-action-borderCheck/Reset button background and border
--yesno-result-neutral, --yesno-result-correct, --yesno-result-wrongResults text colors (neutral, correct, wrong)
--yesno-correct-bg, --yesno-correct-borderCorrect answer highlight
--yesno-wrong-bg, --yesno-wrong-borderWrong answer highlight

These feed into --exercise-action-bg, --exercise-action-border and --exercise-result-* used by ExerciseLayout.

On this page