Tac UIv1.1.2

Radio

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

Import

tsx
import { RadioGroup, Radio } from '@tac-ui/web';

Playground

Interactively configure the Radio group props below.

tsx
<RadioGroup defaultValue="react">
  <Radio radioValue="react" label="React" />
  <Radio radioValue="vue" label="Vue" />
  <Radio radioValue="angular" label="Angular" />
</RadioGroup>

Default Group

RadioGroup manages selection state and provides it via context to child Radio items. Use defaultValue for uncontrolled initial selection.

tsx
<RadioGroup defaultValue="vue">
  <Radio radioValue="react" label="React" id="radio-react" />
  <Radio radioValue="vue" label="Vue" id="radio-vue" />
  <Radio radioValue="angular" label="Angular" id="radio-angular" />
</RadioGroup>

Controlled

Use value and onValueChange on RadioGroup for controlled usage. The callback receives the radioValue string of the newly selected item.

Selected: react
tsx
const [value, setValue] = useState('react');

<RadioGroup value={value} onValueChange={setValue}>
  <Radio radioValue="react" label="React" />
  <Radio radioValue="vue" label="Vue" />
  <Radio radioValue="angular" label="Angular" />
</RadioGroup>

Disabled

Set disabled on individual Radio items to prevent them from being selected while keeping the rest of the group interactive.

tsx
<RadioGroup defaultValue="a">
  <Radio radioValue="a" label="Option A" id="radio-a" />
  <Radio radioValue="b" label="Option B (disabled)" id="radio-b" disabled />
</RadioGroup>

API Reference

RadioGroup

PropTypeDefaultDescription
defaultValuestring-Default selected value for uncontrolled usage.
valuestring-Controlled selected value.
onValueChange(value: string) => void-Called when the selected radio changes.
childrenReact.ReactNode-Radio items to render inside the group.

Radio

PropTypeDefaultDescription
radioValuestring-The value this radio item represents; compared against RadioGroup selection.
labelstring-Label text displayed next to the radio.
idstring-Unique id for the radio input element.
disabledbooleanfalseDisables this radio item when true.