# RadioGroup

> A set of mutually exclusive options, built on real input type=radio elements sharing one name so the browser gives the roving tab stop and keyboard navigation for free.

- Package: `fancy-ui-react` (React 18/19 + Tailwind CSS v4)
- Category: Forms
- Tags: radio, form, selection, compound, validation
- Types: `RadioGroupProps`, `RadioGroupOrientation`, `RadioGroupItemProps`, `RadioGroupContext`
- Docs: https://fancy-ui.rama.app/docs/components/radio-group
- Source: https://github.com/RamaHerbin/fancy-ui/tree/main/react/src/components/radio-group

## Import

```tsx
import { RadioGroup } from 'fancy-ui-react';
```

Setup (once per project): `npm install fancy-ui-react`, then put these lines in your main CSS file (the stylesheet import goes right after `@import "tailwindcss";`):

```css
@import "tailwindcss";
@import "fancy-ui-react/tailwind.css";
```

and import the component styles once in the app entry: `import "fancy-ui-react/styles.css";`. Full guide: https://fancy-ui.rama.app/llms.txt

The names below are the ones to write in React; when one differs from the Svelte name, the Svelte name follows in parentheses. `class` becomes `className`, a callback takes the name the React port declares (`onclick` becomes `onClick`), snippets become `ReactNode` props (render functions when they take arguments) and the default snippet is `children`. Divergences: https://github.com/RamaHerbin/fancy-ui/tree/main/react#divergences-from-the-svelte-api

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `string` | `""` | The selected value, bindable — "" means nothing is selected. |
| `onValueChange` | `(value: string) => void` | — | Called with the new value whenever the selection changes. |
| `name` | `string` | — | Shared name for the native radios. Generated per instance when omitted, so two groups on the same page never fight over each other's selection. |
| `disabled` | `boolean` | `false` | Disables every item in the group. |
| `required` | `boolean` | `false` | Marks the group required for native form validation. |
| `invalid` | `boolean` | `false` | Marks the group invalid — sets aria-invalid. |
| `orientation` | `"horizontal" \| "vertical"` | `"vertical"` | The list's stacking axis. |
| `label` | `string` | — | Accessible name, standalone. Inside a FormField that rendered its own label, its labelId wins instead; a FormField with no label of its own falls back to this. |
| `className` (Svelte `class`) | `string` | — | Additional CSS classes, merged onto the root. |
| `ref` | `HTMLDivElement \| null` | `null` | Bindable reference to the root element. |
| `RadioGroupItem.value` (required) | `string` | — | This item's value — what the group's value becomes when it is picked. |
| `RadioGroupItem.disabled` | `boolean` | `false` | Disables just this item, independent of the group's own disabled. |
| `RadioGroupItem.label` | `string` | — | Visible label text. Also the fallback content, and the fallback name. |
| `RadioGroupItem.className` (Svelte `RadioGroupItem.class`) | `string` | — | Additional CSS classes, merged onto the wrapping label. |
| `RadioGroupItem.ref` | `HTMLInputElement \| null` | `null` | Bindable reference to the item's native input. |
| `sound` | `boolean` | `false` | Plays a select cue when the selection actually changes, once the user has enabled sound |

## Node props

| Prop | Description |
| --- | --- |
| `children` | The RadioGroup's content — the RadioGroupItems. |
| `RadioGroupItem.children` | Custom content rendered in place of the item's label. |

## Example

```tsx
import { useState } from "react";
import { RadioGroup, RadioGroupItem } from "fancy-ui-react";

export function RadioGroupExample() {
	const [plan, setPlan] = useState("starter");

	return (
		<RadioGroup sound value={plan} onValueChange={setPlan} label="Plan">
			<RadioGroupItem value="starter" label="Starter" />
			<RadioGroupItem value="team" label="Team" />
			<RadioGroupItem value="enterprise" label="Enterprise" />
		</RadioGroup>
	);
}
```
