Rost

← All components

component

Radio

One choice out of a few, all on show. A 20px circle with a dot in the picked one, and the words beside it.

In code Contract: review Guidance: proposed Contract on GitHub Figma 733:124 As markdown

Try it

Every variant

Default · Not checked
Disabled · Not checked
Default · Checked
Disabled · Checked

Hover, press or tab to one to see the other 6 states.

Install

npx github:Runceanu/rost add radio

It lands in src/rost/radio/, with what it needs and its contract. Install has the rest.

When to use

  • One out of a few

    Two to five choices where seeing them all helps you pick: how often to invoice, which currency.

When not to use

  • Many choices

    More than five or six, or a list that changes. That's a select, and Rost doesn't have one yet.

  • Switching a view

    Picking which view the screen shows. That's ToggleGroup or Tabs.

    Use ToggleGroup

Behaviour

Put the radios of one question in a <fieldset> with a <legend> that asks it, and give them the same name. The browser does the rest: one picked at a time, and the arrow keys move between them. Empty is a field's edge around the page colour. Picked fills with the primary green, with a dark dot. Disabled fades the row.

Accessibility

  • Element

    A real <input type="radio"> inside a <label>. The input is hidden from sight, not from screen readers.

  • Name

    The words beside it. The <legend> names the group.

  • Keyboard

    Tab reaches the group, on the picked one. The arrow keys move the pick.

  • Focus

    focus-ring around the circle, on :focus-visible.

  • Colour

    Picked isn't only green: the dot is there too. Picked, the edge is the fill's green in dark and a dark green in light, so the circle stands out at 3:1 or more on both.

Content

Short, parallel answers to the legend's question, in sentence case.

Props

PropTypeValuesDefault
checked boolean false
children slot

States: Default, Hover, Pressed, Focus, Disabled.

Values

Straight from the contract. Each value sits next to its token, because six tokens here all come out as #3a3a3a and the colour alone can't tell you which one is right.

Never changes

root

  • gap 8px spacing/gap/small

displayinline-flex · align-itemscenter · vertical-alignmiddle · positionrelative · cursorpointer

input

positionabsolute · width1px · height1px · opacity0 · pointer-eventsnone

box

  • width 20px spacing/size/xsmall
  • height 20px spacing/size/xsmall
  • border-radius 10000px spacing/radius/full
  • outline-width 1px spacing/outline/small
  • outline-offset calc(-1 * var(--spacing-outline-small)) on purpose: Composed from a token: the edge sits inside the box.

positionrelative · flex-shrink0 · outline-stylesolid

dot

  • inset 6px spacing/gap/xsmall
  • border-radius 10000px spacing/radius/full

positionabsolute · pointer-eventsnone

focus-ring

  • border-style solid no token yet
  • border-width 2px spacing/outline/medium
  • border-radius 10000px spacing/radius/full

displaynone · positionabsolute · insetcalc(-1 * var(--spacing-gap-2xsmall)) · pointer-eventsnone

label

  • font-family 'General Sans Variable' font-family/base
  • font-weight 400 typography/paragraph/font-weight/regular
  • font-size 14px typography/paragraph/font-size
  • line-height 20px typography/paragraph/line-height
  • letter-spacing 0px typography/paragraph/letter-spacing
  • color #d3d9d5 radio/label

Changes by variant

10 variants. Each table is what one thing changes with: a column per state, a row per property. Where every row starts with the same token path, it's written once, under the property.

Follows state

Checked

PropertyDefaultHoverPressedFocusDisabled
dot.backgroundradio/on/… default/dot #060805 hover/dot #060805 pressed/dot #060805 focus/dot #060805 disabled/dot #060805

Follows checked

PropertyNot checkedChecked
dot.display none block

Focus

PropertyNot checkedChecked
focus-ring.border-colorradio/… off/focus/focus-ring #999 on/focus/focus-ring #b6ffda

Follows state and checked

Not checked

PropertyDefaultHoverPressedFocusDisabled
box.backgroundradio/off/… default/box #060805 hover/box #171717 pressed/box #171717 focus/box #060805 disabled/box #060805
box.outline-colorradio/off/… default/edge #747573 hover/edge #999999 pressed/edge #999999 focus/edge #747573 disabled/edge #747573

Checked

PropertyDefaultHoverPressedFocusDisabled
box.backgroundradio/on/… default/box #00d669 hover/box #00b450 pressed/box #00913a focus/box #00d669 disabled/box #00d669
box.outline-colorradio/on/… edge #00d669 edge #00d669 edge #00d669 edge #00d669 edge #00d669

Only in some variants

These don't change: they're just set in some variants and not others.

Focus

  • focus-ring.display block layout

Disabled

  • root.cursor default Figma frame size
  • root.opacity 0.24 opacity/gentle