Compare commits

...
1 Commits
Author SHA1 Message Date
Jenna Smith 2adcddac04 [docs] Present Radio docs as Radio Group (#5556) (#5725) 2026-09-15 14:15:01 +01:00
16 changed files with 302 additions and 36 deletions

No files matched your search

+4
View File
@@ -24,3 +24,7 @@
# At the time of adding this rule, there was requirement of at max only a single args[] param
/production-error/:code args\[\]=:args /production-error?code=:code&args[]=:args 301
/production-error/:code /production-error?code=:code 301
# 2026
/react/components/radio /react/components/radio-group 301
@@ -37,7 +37,7 @@ const LONG_LIST = [
{ href: '/react/components/popover', label: 'Popover' },
{ href: '/react/components/preview-card', label: 'Preview Card' },
{ href: '/react/components/progress', label: 'Progress' },
{ href: '/react/components/radio', label: 'Radio' },
{ href: '/react/components/radio-group', label: 'Radio Group' },
{ href: '/react/components/scroll-area', label: 'Scroll Area' },
{ href: '/react/components/select', label: 'Select' },
{ href: '/react/components/separator', label: 'Separator' },
@@ -36,7 +36,7 @@ const LONG_LIST = [
{ href: '/react/components/popover', label: 'Popover' },
{ href: '/react/components/preview-card', label: 'Preview Card' },
{ href: '/react/components/progress', label: 'Progress' },
{ href: '/react/components/radio', label: 'Radio' },
{ href: '/react/components/radio-group', label: 'Radio Group' },
{ href: '/react/components/scroll-area', label: 'Scroll Area' },
{ href: '/react/components/select', label: 'Select' },
{ href: '/react/components/separator', label: 'Separator' },
+11 -8
View File
@@ -27,7 +27,7 @@
- Popover - ([Outline](#popover), [Contents](./popover/page.mdx))
- Preview Card - ([Outline](#preview-card), [Contents](./preview-card/page.mdx))
- Progress - ([Outline](#progress), [Contents](./progress/page.mdx))
- Radio - ([Outline](#radio), [Contents](./radio/page.mdx))
- Radio Group - ([Outline](#radio-group), [Contents](./radio-group/page.mdx))
- Scroll Area - ([Outline](#scroll-area), [Contents](./scroll-area/page.mdx))
- Select - ([Outline](#select), [Contents](./select/page.mdx))
- Separator - ([Outline](#separator), [Contents](./separator/page.mdx))
@@ -1421,15 +1421,15 @@ Displays the status of a task that takes a long time.
[Read more](./progress/page.mdx)
## Radio
## Radio Group
An easily stylable radio button component.
Provides shared state to a series of radio buttons.
<details>
<summary>Outline</summary>
- Keywords: React Radio Button, Radio Group Component, Radio Button, Radio Input, Single Choice, Exclusive Choice, Mutually Exclusive, Option Selector, Option Button, Form Radio Control, Accessible Radio Group, Customizable Radio, Headless React Components, Base UI
- Keywords: React Radio Group, Radio Group Component, Grouped Radio Buttons, React Radio Button, Radio Button, Radio Input, Single Choice, Exclusive Choice, Mutually Exclusive, Option Selector, Option Button, Form Radio Control, Accessible Radio Group, Customizable Radio, Headless React Components, Base UI
- Sections:
- Usage guidelines
- Anatomy
@@ -1442,17 +1442,20 @@ An easily stylable radio button component.
- Root
- Indicator
- Exports:
- Radio - Root
- Radio Group - Root
- Props: className, disabled, inputRef, nativeButton, readOnly, render, required, style, value
- Data Attributes: data-checked, data-dirty, data-disabled, data-filled, data-focused, data-invalid, data-readonly, data-required, data-touched, data-unchecked, data-valid
- Radio - Indicator
- Radio Group - Indicator
- Props: className, keepMounted, render, style
- Data Attributes: data-checked, data-dirty, data-disabled, data-ending-style, data-filled, data-focused, data-invalid, data-readonly, data-required, data-starting-style, data-touched, data-unchecked, data-valid
- Types: Radio.Indicator.Props, Radio.Indicator.State, Radio.Root.Props, Radio.Root.State
- RadioGroup
- Props: className, defaultValue, disabled, form, inputRef, name, onValueChange, readOnly, render, required, style, value
- Data Attributes: data-disabled
- Types: Radio.Indicator.Props, Radio.Indicator.State, Radio.Root.Props, Radio.Root.State, RadioGroup.ChangeEventDetails, RadioGroup.ChangeEventReason, RadioGroup.Props, RadioGroup.State
</details>
[Read more](./radio/page.mdx)
[Read more](./radio-group/page.mdx)
## Scroll Area
@@ -1,9 +1,9 @@
# Radio
# Radio Group
<Subtitle>An easily stylable radio button component.</Subtitle>
<Subtitle>Provides shared state to a series of radio buttons.</Subtitle>
<Meta
name="description"
content="A high-quality, unstyled React radio button component that is easy to style."
content="A high-quality, unstyled React radio group component that provides shared state to a series of radio buttons."
/>
import { DemoRadioHero } from './demos/hero';
@@ -16,7 +16,7 @@ import { DemoRadioHero } from './demos/hero';
## Anatomy
Radio is always placed within Radio Group. Import the components and place them together:
Import the component and assemble its parts:
```jsx title="Anatomy"
import { Radio } from '@base-ui/react/radio';
@@ -119,26 +119,24 @@ Use [Field](/react/components/field) and [Fieldset](/react/components/fieldset)
### RadioGroup
import { TypesRadioGroup } from '../radio-group/types';
import { TypesRadioGroup } from './types';
Provides a shared state to a series of radio buttons. Renders a `<div>` element.
<TypesRadioGroup />
import { TypesRadio } from './types';
<TypesRadioGroup.RadioGroup />
### Root
<TypesRadio.Root />
<TypesRadioGroup.Root />
### Indicator
<TypesRadio.Indicator />
<TypesRadioGroup.Indicator />
export const metadata = {
keywords: [
'React Radio Button',
'React Radio Group',
'Radio Group Component',
'Grouped Radio Buttons',
'React Radio Button',
'Radio Button',
'Radio Input',
'Single Choice',
@@ -4,9 +4,136 @@
## API Reference
### Root
Represents the radio button itself.
Renders a `<span>` element and a hidden `<input>` beside.
**Root Props:**
| Prop | Type | Default | Description |
| :----------- | :--------------------------------------------------------------------------------------- | :------ | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| value\* | `Value` | - | The unique identifying value of the radio in a group. |
| nativeButton | `boolean` | `false` | Whether the component renders a native `<button>` element when replacing it&#xA;via the `render` prop.&#xA;Set to `true` if the rendered element is a native button. |
| disabled | `boolean` | - | Whether the component should ignore user interaction. |
| readOnly | `boolean` | - | Whether the user should be unable to select the radio button. |
| required | `boolean` | - | Whether the user must choose a value before submitting a form. |
| inputRef | `React.Ref<HTMLInputElement>` | - | A ref to access the hidden input element. |
| className | `string \| ((state: Radio.Root.State) => string \| undefined)` | - | CSS class applied to the element, or a function that&#xA;returns a class based on the component's state. |
| style | `React.CSSProperties \| ((state: Radio.Root.State) => React.CSSProperties \| undefined)` | - | Style applied to the element, or a function that&#xA;returns a style object based on the component's state. |
| render | `ReactElement \| ((props: HTMLProps, state: Radio.Root.State) => ReactElement)` | - | Allows you to replace the component's HTML element&#xA;with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
**Root Data Attributes:**
| Attribute | Type | Description |
| :------------- | :--- | :-------------------------------------------------------------------------- |
| data-checked | - | Present when the radio is checked. |
| data-unchecked | - | Present when the radio is not checked. |
| data-disabled | - | Present when the radio is disabled. |
| data-readonly | - | Present when the radio is readonly. |
| data-required | - | Present when the radio is required. |
| data-valid | - | Present when the radio is in a valid state (when wrapped in Field.Root). |
| data-invalid | - | Present when the radio is in an invalid state (when wrapped in Field.Root). |
| data-dirty | - | Present when the radio's value has changed (when wrapped in Field.Root). |
| data-touched | - | Present when the radio has been touched (when wrapped in Field.Root). |
| data-filled | - | Present when the radio is checked (when wrapped in Field.Root). |
| data-focused | - | Present when the radio is focused (when wrapped in Field.Root). |
### Root.Props
Re-export of [Root](#root) props.
### Root.State
```typescript
type RadioRootState = {
/** Whether the radio button is currently selected. */
checked: boolean;
/** Whether the component should ignore user interaction. */
disabled: boolean;
/** Whether the user should be unable to select the radio button. */
readOnly: boolean;
/** Whether the user must choose a value before submitting a form. */
required: boolean;
/** Whether the radio button has been touched (when wrapped in Field.Root). */
touched: boolean;
/** Whether the radio button's value has changed from its initial value (when wrapped in Field.Root). */
dirty: boolean;
/** Whether the radio button is in a valid state (when wrapped in Field.Root). */
valid: boolean | null;
/** Whether the radio button has a value (when wrapped in Field.Root). */
filled: boolean;
/** Whether the radio button is focused (when wrapped in Field.Root). */
focused: boolean;
};
```
### Indicator
Indicates whether the radio button is selected.
Renders a `<span>` element.
**Indicator Props:**
| Prop | Type | Default | Description |
| :---------- | :-------------------------------------------------------------------------------------------- | :------ | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| className | `string \| ((state: Radio.Indicator.State) => string \| undefined)` | - | CSS class applied to the element, or a function that&#xA;returns a class based on the component's state. |
| style | `React.CSSProperties \| ((state: Radio.Indicator.State) => React.CSSProperties \| undefined)` | - | Style applied to the element, or a function that&#xA;returns a style object based on the component's state. |
| keepMounted | `boolean` | `false` | Whether to keep the HTML element in the DOM when the radio button is inactive. |
| render | `ReactElement \| ((props: HTMLProps, state: Radio.Indicator.State) => ReactElement)` | - | Allows you to replace the component's HTML element&#xA;with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
**Indicator Data Attributes:**
| Attribute | Type | Description |
| :------------------ | :--- | :-------------------------------------------------------------------------- |
| data-checked | - | Present when the radio is checked. |
| data-unchecked | - | Present when the radio is not checked. |
| data-disabled | - | Present when the radio is disabled. |
| data-readonly | - | Present when the radio is readonly. |
| data-required | - | Present when the radio is required. |
| data-valid | - | Present when the radio is in a valid state (when wrapped in Field.Root). |
| data-invalid | - | Present when the radio is in an invalid state (when wrapped in Field.Root). |
| data-dirty | - | Present when the radio's value has changed (when wrapped in Field.Root). |
| data-touched | - | Present when the radio has been touched (when wrapped in Field.Root). |
| data-filled | - | Present when the radio is checked (when wrapped in Field.Root). |
| data-focused | - | Present when the radio is focused (when wrapped in Field.Root). |
| data-starting-style | - | Present when the radio indicator begins animating in. |
| data-ending-style | - | Present when the radio indicator is animating out. |
### Indicator.Props
Re-export of [Indicator](#indicator) props.
### Indicator.State
```typescript
type RadioIndicatorState = {
/** The transition status of the component. */
transitionStatus: TransitionStatus;
/** Whether the radio button is currently selected. */
checked: boolean;
/** Whether the component should ignore user interaction. */
disabled: boolean;
/** Whether the user should be unable to select the radio button. */
readOnly: boolean;
/** Whether the user must choose a value before submitting a form. */
required: boolean;
/** Whether the radio button has been touched (when wrapped in Field.Root). */
touched: boolean;
/** Whether the radio button's value has changed from its initial value (when wrapped in Field.Root). */
dirty: boolean;
/** Whether the radio button is in a valid state (when wrapped in Field.Root). */
valid: boolean | null;
/** Whether the radio button has a value (when wrapped in Field.Root). */
filled: boolean;
/** Whether the radio button is focused (when wrapped in Field.Root). */
focused: boolean;
};
```
### RadioGroup
Provides a shared state to a series of radio buttons.
Provides shared state to a series of radio buttons.
Renders a `<div>` element.
**RadioGroup Props:**
@@ -86,11 +213,140 @@ type RadioGroupChangeEventDetails = {
};
```
## Additional Types
### RadioIndicatorProps
```typescript
type RadioIndicatorProps = {
/**
* Whether to keep the HTML element in the DOM when the radio button is inactive.
* @default false
*/
keepMounted?: boolean;
/**
* CSS class applied to the element, or a function that
* returns a class based on the component's state.
*/
className?: string | ((state: Radio.Indicator.State) => string | undefined);
/**
* Allows you to replace the component's HTML element
* with a different tag, or compose it with another component.
*
* Accepts a `ReactElement` or a function that returns the element to render.
*/
render?: ReactElement | ((props: HTMLProps, state: Radio.Indicator.State) => ReactElement);
/**
* Style applied to the element, or a function that
* returns a style object based on the component's state.
*/
style?: React.CSSProperties | ((state: Radio.Indicator.State) => React.CSSProperties | undefined);
};
```
### RadioIndicatorState
```typescript
type RadioIndicatorState = {
/** The transition status of the component. */
transitionStatus: TransitionStatus;
/** Whether the radio button is currently selected. */
checked: boolean;
/** Whether the component should ignore user interaction. */
disabled: boolean;
/** Whether the user should be unable to select the radio button. */
readOnly: boolean;
/** Whether the user must choose a value before submitting a form. */
required: boolean;
/** Whether the radio button has been touched (when wrapped in Field.Root). */
touched: boolean;
/** Whether the radio button's value has changed from its initial value (when wrapped in Field.Root). */
dirty: boolean;
/** Whether the radio button is in a valid state (when wrapped in Field.Root). */
valid: boolean | null;
/** Whether the radio button has a value (when wrapped in Field.Root). */
filled: boolean;
/** Whether the radio button is focused (when wrapped in Field.Root). */
focused: boolean;
};
```
### RadioRootProps
```typescript
type RadioRootProps<Value = any> = {
/** The unique identifying value of the radio in a group. */
value: Value;
/** Whether the component should ignore user interaction. */
disabled?: boolean;
/** Whether the user must choose a value before submitting a form. */
required?: boolean;
/** Whether the user should be unable to select the radio button. */
readOnly?: boolean;
/** A ref to access the hidden input element. */
inputRef?: React.Ref<HTMLInputElement>;
/**
* Whether the component renders a native `<button>` element when replacing it
* via the `render` prop.
* Set to `true` if the rendered element is a native button.
* @default false
*/
nativeButton?: boolean;
/**
* CSS class applied to the element, or a function that
* returns a class based on the component's state.
*/
className?: string | ((state: Radio.Root.State) => string | undefined);
/**
* Style applied to the element, or a function that
* returns a style object based on the component's state.
*/
style?: React.CSSProperties | ((state: Radio.Root.State) => React.CSSProperties | undefined);
/**
* Allows you to replace the component's HTML element
* with a different tag, or compose it with another component.
*
* Accepts a `ReactElement` or a function that returns the element to render.
*/
render?: ReactElement | ((props: HTMLProps, state: Radio.Root.State) => ReactElement);
};
```
### RadioRootState
```typescript
type RadioRootState = {
/** Whether the radio button is currently selected. */
checked: boolean;
/** Whether the component should ignore user interaction. */
disabled: boolean;
/** Whether the user should be unable to select the radio button. */
readOnly: boolean;
/** Whether the user must choose a value before submitting a form. */
required: boolean;
/** Whether the radio button has been touched (when wrapped in Field.Root). */
touched: boolean;
/** Whether the radio button's value has changed from its initial value (when wrapped in Field.Root). */
dirty: boolean;
/** Whether the radio button is in a valid state (when wrapped in Field.Root). */
valid: boolean | null;
/** Whether the radio button has a value (when wrapped in Field.Root). */
filled: boolean;
/** Whether the radio button is focused (when wrapped in Field.Root). */
focused: boolean;
};
```
## Export Groups
- `RadioGroup`: `RadioGroup`, `RadioGroup.State`, `RadioGroup.Props`, `RadioGroup.ChangeEventReason`, `RadioGroup.ChangeEventDetails`, `RadioGroupState`, `RadioGroupProps`, `RadioGroupChangeEventReason`, `RadioGroupChangeEventDetails`
- `Radio`: `Radio.Root`, `Radio.Root.State`, `Radio.Root.Props`, `Radio.Indicator`, `Radio.Indicator.Props`, `Radio.Indicator.State`, `RadioRootState`, `RadioRootProps`, `RadioIndicatorProps`, `RadioIndicatorState`
## Canonical Types
Maps `Canonical`: `Alias` — Use Canonical when its namespace is already imported; otherwise use Alias.
- `RadioGroup.State`: `RadioGroupState`
- `RadioGroup.Props`: `RadioGroupProps`
- `RadioGroup.ChangeEventReason`: `RadioGroupChangeEventReason`
- `RadioGroup.ChangeEventDetails`: `RadioGroupChangeEventDetails`
- `RadioGroup.State` (`RadioGroup`): `RadioGroupState`
- `RadioGroup.Props` (`RadioGroup`): `RadioGroupProps`
- `RadioGroup.ChangeEventReason` (`RadioGroup`): `RadioGroupChangeEventReason`
- `RadioGroup.ChangeEventDetails` (`RadioGroup`): `RadioGroupChangeEventDetails`
@@ -1,4 +1,7 @@
import { Radio } from '@base-ui/react/radio';
import { RadioGroup } from '@base-ui/react/radio-group';
import { createTypes } from 'docs/src/utils/createTypes';
import { createMultipleTypes } from 'docs/src/utils/createTypes';
export const TypesRadioGroup = createTypes(import.meta.url, RadioGroup, { excludeFromIndex: true });
const { types } = createMultipleTypes(import.meta.url, { RadioGroup, Radio });
export const TypesRadioGroup = types;
@@ -1,7 +1,9 @@
import { Radio } from '@base-ui/react/radio';
import { createMultipleTypes } from 'docs/src/utils/createTypes';
const { types, AdditionalTypes } = createMultipleTypes(import.meta.url, Radio);
const { types, AdditionalTypes } = createMultipleTypes(import.meta.url, Radio, {
excludeFromIndex: true,
});
export const TypesRadio = types;
export const TypesRadioAdditional = AdditionalTypes;
+1 -1
View File
@@ -82,7 +82,7 @@ No description available
- Popover
- Preview Card
- Progress
- Radio
- Radio Group
- Scroll Area
- Select
- Separator
@@ -23,10 +23,10 @@ import { REASONS } from '../internals/reasons';
const MODIFIER_KEYS = [SHIFT];
/**
* Provides a shared state to a series of radio buttons.
* Provides shared state to a series of radio buttons.
* Renders a `<div>` element.
*
* Documentation: [Base UI Radio Group](https://base-ui.com/react/components/radio)
* Documentation: [Base UI Radio Group](https://base-ui.com/react/components/radio-group)
*/
export const RadioGroup = React.forwardRef(function RadioGroup<Value>(
componentProps: RadioGroup.Props<Value>,
@@ -12,7 +12,7 @@ import { type TransitionStatus, useTransitionStatus } from '../../internals/useT
* Indicates whether the radio button is selected.
* Renders a `<span>` element.
*
* Documentation: [Base UI Radio](https://base-ui.com/react/components/radio)
* Documentation: [Base UI Radio](https://base-ui.com/react/components/radio-group)
*/
export const RadioIndicator = React.forwardRef(function RadioIndicator(
componentProps: RadioIndicator.Props,
+1 -1
View File
@@ -29,7 +29,7 @@ import { RadioRootContext } from './RadioRootContext';
* Represents the radio button itself.
* Renders a `<span>` element and a hidden `<input>` beside.
*
* Documentation: [Base UI Radio](https://base-ui.com/react/components/radio)
* Documentation: [Base UI Radio](https://base-ui.com/react/components/radio-group)
*/
export const RadioRoot = React.forwardRef(function RadioRoot<Value>(
componentProps: RadioRoot.Props<Value>,