Radio card
A radio option presented as a card, for choices that need a title and a short description.
RadioCard only draws the card. It must be used inside a RadioGroup, which
owns the selected value, the disabled state and the keyboard navigation.
When to use
- To choose one option where each needs a title and a description, such as the review mode of a task.
- When the options are few and a large target helps.
When not to use
- Plain options with short labels. Use Radio group.
- Picking several options. Use Checkbox card.
- More than six options. Use Select.
- A filter the user can clear. Use Radio filter.
States
One card selected and one disabled, in the same group.
Disabled group
Read only
Content
- The title names the option: “Revisão por amostragem”.
- The description says what changes when it is chosen, in one sentence.
- Build the content with
Typographyspans. Do not put buttons or links in the card: the whole card is one control.
Do and don’t
Accessibility
- Built on Radix Radio Group: the group is
role="radiogroup"and each card is onerole="radio"control witharia-checked. Tabenters the group at the selected card. Arrow keys move focus and selection, skip disabled cards and wrap at the ends.Spaceselects the focused card.- Name the group with
aria-labeloraria-labelledby. The card text is its accessible name. Usearia-labelledbyandaria-describedbyon the card to point at the title and the description. - The selected card shows a filled dot, a border and a background, so selection does not rely on color alone.
aria-readonlyon the group only changes the style. Ignore the change inonValueChange.
Code
import { RadioCard } from "@repo/ui/radio-card";
import { RadioGroup } from "@repo/ui/radio-group";
import { Typography } from "@repo/ui/typography";
<RadioGroup aria-label="Modo de revisão" onValueChange={setMode} value={mode}>
<RadioCard value="completa">
<Typography as="span" variant="labelSm">
Revisão completa
</Typography>
</RadioCard>
</RadioGroup>;
Props
RadioCard| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | The card content. Compose a title and a description, and avoid nested interactive controls |
disabled | boolean | false | Disables this card and dims it |
value | string | — | Unique value of this card inside the group |
Every other prop of the Radix Radio Group item, such as id and required, is
forwarded. asChild is not available.
Known issues
| Issue | Effect |
|---|---|
Disabled is disabled:opacity-50 on the whole card. |
A translucent card, against the no-transparency rule. The text contrast can fall below AA. |
aria-readonly is styled but not enforced. |
A read-only group still changes selection unless the app ignores the change. |
No style for aria-invalid. |
A group of cards cannot show a validation error. |
The focus ring has ring-offset-2 with no offset color token. |
The offset falls back to Tailwind’s default, white. |