> For the complete documentation index, see [llms.txt](https://docs.rierino.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rierino.com/sdk-core-ui/components/radio-group.md). Agents can also search and read this documentation through its [MCP server](https://docs.rierino.com/~gitbook/mcp).

# RadioGroup

Lets people pick exactly one option from a short list.

{% code title="radio-group/demo.tsx" %}

```tsx
import { useState } from "react";
import { Radio, RadioGroup } from "@rierino-open/core-ui";

export default function RadioGroupDemo() {
  const [shipping, setShipping] = useState("standard");

  return (
    <RadioGroup label="Shipping" value={shipping} onChange={setShipping}>
      <Radio value="standard">Standard</Radio>
      <Radio value="express">Express</Radio>
      <Radio value="pickup">Store pickup</Radio>
    </RadioGroup>
  );
}
```

{% endcode %}

## Usage

{% tabs %}
{% tab title="React app" %}

```tsx
import { Radio, RadioGroup } from '@rierino-open/core-ui';

<RadioGroup label="Shipping" value={shipping} onChange={setShipping}>
  <Radio value="standard">Standard</Radio>
  <Radio value="express">Express</Radio>
</RadioGroup>
```

{% endtab %}

{% tab title="Hosted editor" %}

```jsx
import CoreUI from '@rierino-open/core-ui';
const { Radio, RadioGroup } = CoreUI;

<RadioGroup label="Shipping" value={shipping} onChange={setShipping}>
  <Radio value="standard">Standard</Radio>
  <Radio value="express">Express</Radio>
</RadioGroup>
```

{% endtab %}
{% endtabs %}

The group's value is the selected `Radio`'s `value`, and `onChange` receives it as a string. Use `value` for a controlled group, or `defaultValue` to let it manage its own state.

Unlike Checkbox and Switch, `Radio` renders its `children` as its label, and `RadioGroup` renders `label` as the group's label.

For long lists, or when space is tight, use [Autocomplete](https://docs.rierino.com/sdk-core-ui/components/autocomplete.md) with `selectionMode="single"` instead.

## Examples

### Descriptions

`description` on a `Radio` adds help text under its label. `description` on the group adds it below all the options.

{% code title="radio-group/descriptions.tsx" %}

```tsx
import { Radio, RadioGroup } from "@rierino-open/core-ui";

export default function RadioGroupDescriptions() {
  return (
    <RadioGroup label="Visibility" defaultValue="public" description="You can change this later.">
      <Radio value="public" description="Anyone can find and buy the product.">
        Public
      </Radio>
      <Radio value="hidden" description="Only people with the link can see it.">
        Hidden
      </Radio>
      <Radio value="draft" description="Only your team can see it.">
        Draft
      </Radio>
    </RadioGroup>
  );
}
```

{% endcode %}

### Horizontal

`orientation="horizontal"` lays the options out in a row, wrapping when there isn't room. The arrow keys follow the orientation.

{% code title="radio-group/horizontal.tsx" %}

```tsx
import { Radio, RadioGroup } from "@rierino-open/core-ui";

export default function RadioGroupHorizontal() {
  return (
    <RadioGroup label="Size" orientation="horizontal" defaultValue="m">
      <Radio value="s">S</Radio>
      <Radio value="m">M</Radio>
      <Radio value="l">L</Radio>
      <Radio value="xl">XL</Radio>
    </RadioGroup>
  );
}
```

{% endcode %}

### Disabled

Disable one option with `isDisabled` on the `Radio`, or the whole group with `isDisabled` on `RadioGroup`.

{% code title="radio-group/disabled.tsx" %}

```tsx
import { Radio, RadioGroup } from "@rierino-open/core-ui";

export default function RadioGroupDisabled() {
  return (
    <div style={{ display: "flex", gap: 48 }}>
      <RadioGroup label="One option disabled" defaultValue="card">
        <Radio value="card">Card</Radio>
        <Radio value="transfer">Bank transfer</Radio>
        <Radio value="cash" isDisabled>
          Cash on delivery
        </Radio>
      </RadioGroup>

      <RadioGroup label="Whole group disabled" defaultValue="card" isDisabled>
        <Radio value="card">Card</Radio>
        <Radio value="transfer">Bank transfer</Radio>
      </RadioGroup>
    </div>
  );
}
```

{% endcode %}

### Validation

Set `isInvalid` and pass `errorMessage`, which is shown below the options while the group is invalid.

{% code title="radio-group/validation.tsx" %}

```tsx
import { useState } from "react";
import { Radio, RadioGroup } from "@rierino-open/core-ui";

export default function RadioGroupValidation() {
  const [plan, setPlan] = useState<string | null>(null);

  return (
    <RadioGroup
      label="Plan"
      value={plan}
      onChange={setPlan}
      isInvalid={plan === null}
      errorMessage="Choose a plan to continue."
    >
      <Radio value="basic">Basic</Radio>
      <Radio value="pro">Pro</Radio>
    </RadioGroup>
  );
}
```

{% endcode %}

## Accessibility

* Renders native radio inputs in a `radiogroup`, labelled by the group's `label`. Give the group a `label`, or `aria-label` when it has no visible one.
* **Keyboard:** `Tab` moves into the group, onto the selected option. The arrow keys move between options and select them. `Tab` again leaves the group.
* An option's `description` is linked to it, so screen readers read it after the label.
* **There is no visible keyboard focus yet.** The focus ring the styles intend doesn't render, so a focused option looks the same as an unfocused one.

## Styling

| Attribute            | On           | Present when                                 |
| -------------------- | ------------ | -------------------------------------------- |
| `data-orientation`   | Group        | `horizontal` or `vertical`                   |
| `data-disabled`      | Group, Radio | `isDisabled` is set; options are also dimmed |
| `data-invalid`       | Group, Radio | `isInvalid` is set                           |
| `data-selected`      | Radio        | The option is selected                       |
| `data-focus-visible` | Radio        | The option has keyboard focus                |

The circle uses `--border-color` when not selected, and `--primary` for its border and dot when selected. See [theme variables](https://docs.rierino.com/sdk-core-ui/foundations/colors.md#theme-variables). `descriptionClassName` styles an option's description.

## API reference

### RadioGroup

| Prop           | Type                                                   | Default      | Description                                                                                                                                                                        |
| -------------- | ------------------------------------------------------ | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `name`         | `string`                                               |              | The name of the input element, used when submitting an HTML form. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefname).                      |
| `isRequired`   | `boolean`                                              |              | Whether user input is required on the input before form submission.                                                                                                                |
| `isInvalid`    | `boolean`                                              |              | Whether the input value is invalid.                                                                                                                                                |
| `isDisabled`   | `boolean`                                              |              | Whether the input is disabled.                                                                                                                                                     |
| `isReadOnly`   | `boolean`                                              |              | Whether the input can be selected but not changed by the user.                                                                                                                     |
| `value`        | `string \| null`                                       |              | The current value (controlled).                                                                                                                                                    |
| `defaultValue` | `string \| null`                                       |              | The default value (uncontrolled).                                                                                                                                                  |
| `onChange`     | `((value: string) => void)`                            |              | Handler that is called when the value changes.                                                                                                                                     |
| `orientation`  | `Orientation`                                          | `'vertical'` | The axis the Radio Button(s) should align with.                                                                                                                                    |
| `className`    | `string \| ((state) => string)`                        |              | The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. A function may be provided to compute the class based on component state. |
| `label`        | `string`                                               |              | The group's visible label, shown above the options.                                                                                                                                |
| `description`  | `string`                                               |              | Help text shown below the options.                                                                                                                                                 |
| `errorMessage` | `string \| ((validation: ValidationResult) => string)` |              | Shown below the options while the group is invalid (`isInvalid`).                                                                                                                  |

### Radio

| Prop                   | Type                                  | Default | Description                                                                                                                                                                        |
| ---------------------- | ------------------------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `value`                | `string`                              |         | **Required.** The value of the radio button, used when submitting an HTML form. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/radio#Value).            |
| `isDisabled`           | `boolean`                             |         | Whether the radio button is disabled or not. Shows that a selection exists, but is not available in that circumstance.                                                             |
| `className`            | `string \| ((state) => string)`       |         | The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. A function may be provided to compute the class based on component state. |
| `children`             | `ReactNode \| ((state) => ReactNode)` |         | The children of the component. A function may be provided to alter the children based on component state.                                                                          |
| `description`          | `string`                              |         | Help text shown under the option's label, and announced with it by screen readers.                                                                                                 |
| `descriptionClassName` | `string`                              |         | Classes added to the description text.                                                                                                                                             |

Both also accept the other props of React Aria's [RadioGroup](https://react-spectrum.adobe.com/react-aria/RadioGroup.html#props).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.rierino.com/sdk-core-ui/components/radio-group.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
