Skip to content

Radio

One choice among a few that exclude each other, with all of them visible so they can be compared.

import { Radio } from '@sypnia/ui/react'

On this page
  1. A choice with explanations
  2. Short options in a row
  3. A disabled option
  4. When to use it
  5. For everyone
  6. Props

A choice with explanations

Each option says what it means. Arrow keys move the choice.

Who can read the table orders
Code
import { useState, type ChangeEvent } from 'react';
import { Fieldset, Radio } from '@sypnia/ui/react';

// Arrow keys move the choice; Tab leaves the group.
export default function Group() {
  const [access, setAccess] = useState('team');
  const pick = (e: ChangeEvent<HTMLInputElement>) => setAccess(e.target.value);
  return (
    <Fieldset legend="Who can read the table orders">
      <Radio name="access" value="team" label="Only the team" description="People you invited to this project." checked={access === 'team'} onChange={pick} />
      <Radio name="access" value="signed-in" label="Anyone signed in to your app" description="Your access rules decide which rows each person sees." checked={access === 'signed-in'} onChange={pick} />
      <Radio name="access" value="public" label="Anyone with the address" description="No sign-in needed. Use it for public catalogues only." checked={access === 'public'} onChange={pick} />
    </Fieldset>
  );
}

Short options in a row

Three one-word options side by side.

Export format
Code
import { Fieldset, Radio } from '@sypnia/ui/react';

export default function Short() {
  return (
    <Fieldset legend="Export format">
      <div className="sy-row">
        <Radio name="format" value="csv" label="CSV" defaultChecked />
        <Radio name="format" value="json" label="JSON" />
        <Radio name="format" value="sql" label="SQL" />
      </div>
    </Fieldset>
  );
}

A disabled option

The option that is not available says why.

Backups
Code
import { Fieldset, Radio } from '@sypnia/ui/react';

export default function States() {
  return (
    <Fieldset legend="Backups">
      <Radio name="backups" value="daily" label="Every night" description="Kept for 7 days." defaultChecked />
      <Radio name="backups" value="weekly" label="Every Sunday" description="Kept for 4 weeks." />
      <Radio name="backups" value="hourly" label="Every hour" description="Available on the Pro plan." disabled />
    </Fieldset>
  );
}

When to use it

Use it when

  • Two to five options, and exactly one must be chosen.
  • The options need a line of explanation each: use description.
  • Always inside a Fieldset whose legend is the question, and with the same name on every Radio.

Do not use it when

  • Several can be chosen at once: Checkbox.
  • It is simply on or off: Checkbox or Switch.
  • There are many options: NativeSelect or Combobox take less room.
  • It switches between views of the same thing: SegmentedControl or Tabs.

For everyone

  • The group is one Tab stop; arrow keys move between options and choose as they move.
  • The legend of the Fieldset is read when focus enters the group, then the option and its position («1 of 3»).
  • Start with the safest option chosen, unless choosing for the person would be wrong.

Props

RadioTypeDefault
labelrequired ReactNode
description ReactNode
  1. A choice with explanations
  2. Short options in a row
  3. A disabled option
  4. When to use it
  5. For everyone
  6. Props

    Search pages, sections and terms