Components

Radio

Radios are used when only one choice may be selected in a series of options.

If options are not mutually exclusive, or there is a single option, use a checkbox instead.

Import

  • Radio: The radio button component
  • RadioGroup: A wrapper that groups radio buttons
import { Radio, RadioGroup } from '@outfitio/outkit';

Usage

Radios must always be rendered within a radioGroup component.

You can also display the radio group horizontally by passing the isInline prop.

Disabled radios

Invalid radio

Radio sizes

Pass the size prop to change the size of the Radio. Values can be either sm, md or lg.

Accessibility

  • Screen readers convey the state of the radio automatically.
  • Use the disabled prop to apply the HTML disabled attribute to the radio input. This prevents users from being able to interact with the radio, and conveys its inactive state to assistive technologies.
  • In the event there is no visible label for the radio, use the aria-label prop to provide a label for assistive technologies. Alternatively, use aria-labelledby to point to an alternate label.
  • Move focus to the radio button group using the tab key (or shift + tab when tabbing backwards). Use the up and down arrow keys to change which radio button is selected.

Best Practice

Radio buttons should:

  • Always be part of a radio group that includes at least two or more choices, where users can only select one option
  • Have a default option selected when possible
  • Be organised in a logical order, such as alphabetical, numerical, time-based, or another clear system
  • Be used with an associated label component
  • Use sentence case for radio labels, where the first word is capitalised and the rest are lowercase, unless the term is a proper noun

Props

NameTypeDefaultDescription
idstringThe id assigned to input field
namestringThe name of the input field in a radio (Useful for form submission)
valuestring or numberThe value to be used in the radio input. This is the value that will be returned on form submission
variantColorstringThe color of the radio when it's checked. This should be one of the color keys in the theme (e.g."green", "red")
defaultIsCheckedbooleanIf true, the radio will be initially checked
isCheckedbooleanIf true, the radio will be checked. You'll need to pass onChange to update it's value (since it's now controlled)
isFullWidthbooleanIf true, the radio should take up the full width of the parent
sizesm, md, lgmdThe size (width and height) of the radio
isDisabledbooleanIf true, the radio will be disabled
isInvalidbooleanIf true, the radio is marked as invalid. Changes style of unchecked state
childrenReact.ReactNodeThe children of the radio
onChangefunctionFunction called when the state of the radio changes
onBlurfunctionFunction called when you blur out of the radio
onFocusfunctionFunction called when the radio receive focus
aria-labelstringAn accessible label for the radio in event there's no visible label or children was passed
aria-labelledbystringId that points to the label for the radio in event no children was passed