Radio

A set of mutually exclusive options where only one can be selected at a time.

Anatomy

<script>
  import {
    Radio,
    RadioGroup,
    RadioItem,
    RadioItemControl,
    RadioItemText,
    RadioIndicator,
    RadioItemHiddenInput,
    RadioLabel,
  } from "@saas-ui/svelte/components/radio";
</script>

<Radio.Group>
  <Radio.Label>Select an option</Radio.Label>
  <Radio.Item value="option1">
    <Radio.ItemControl>
      <Radio.Indicator />
    </Radio.ItemControl>
    <Radio.ItemText>Option 1</Radio.ItemText>
    <Radio.ItemHiddenInput />
  </Radio.Item>
  <Radio.Item value="option2">
    <Radio.ItemControl>
      <Radio.Indicator />
    </Radio.ItemControl>
    <Radio.ItemText>Option 2</Radio.ItemText>
    <Radio.ItemHiddenInput />
  </Radio.Item>
</Radio.Group>

Examples

Basic Accessibility

Basic radio group with default styling.

Colours Accessibility

Use the colour prop to change the colour of the radio buttons.

Composition Accessibility

Use the composition API for full control over the radio button structure.

Controlled Accessibility

Use the value and onValueChange props to control the selected value.

Disabled Accessibility

Use the disabled prop to disable a radio item or the entire group.

Orientation Accessibility

Use the orientation prop to change the layout direction of the radio group.

Sizes Accessibility

Use the size prop to change the size of the radio buttons.

Variants Accessibility

Use the variant prop to change the visual style of the radio buttons.

With Label Accessibility

Use Radio.Label to add a label to the radio group.

Props

Radio.Group

The radio group container that manages state and context.

Prop Type Default Description
children Snippet - Content to render inside the radio group.
class string - Additional CSS classes to apply.
size "sm" | "md" | "lg" "md" The size of the radio buttons.
variant "solid" | "subtle" | "outline" "solid" The visual style of the radio buttons.
colour ColourName "indigo" The colour palette of the radio buttons.
value string - The controlled value of the radio group.
defaultValue string - The default value when uncontrolled.
name string - The name of the input fields (used for form submission).
orientation "horizontal" | "vertical" "vertical" Layout orientation of the radio group.
disabled boolean false Whether the radio group is disabled.
invalid boolean false Whether the radio group is in an invalid state.
readOnly boolean false Whether the radio group is read-only.
onValueChange (details: { value: string | null }) => void - Callback invoked when the value changes.

Radio.Item

An individual radio item within the group.

Prop Type Default Description
children Snippet - Content to render inside the radio item (composition API).
label string - The label text displayed next to the radio.
class string - Additional CSS classes to apply.
value string - The value of this radio item.
disabled boolean false Whether this radio item is disabled.
invalid boolean false Whether this radio item is invalid.

Radio.ItemControl

The visual control element for the radio (the circular button).

Prop Type Default Description
children Snippet - The content of the control (usually indicators).
class string - Additional classes to apply to the control.

Radio.Indicator

The indicator element that shows when the radio is selected.

Prop Type Default Description
children Snippet - Optional custom content for the indicator.
class string - Additional classes to apply to the indicator.

Radio.ItemText

The text label for a radio item.

Prop Type Default Description
children Snippet - The content of the label.
class string - Additional classes to apply to the label.

Radio.ItemHiddenInput

A hidden input element for form submission and accessibility.

Prop Type Default Description

Radio.Label

A label for the entire radio group.

Prop Type Default Description
children Snippet - The content of the group label.
class string - Additional classes to apply to the label.