Getting Started
Components
- Advanced Toast
- ArrowButton
- Arrows
- Avatar
- Backdrop
- Basic Toast
- Breadcrumb
- Button
- CardBackground
- Card
- ChatButton
- Checkbox
- Checkboxes
- Chip
- ChoiceExpander
- Clickable
- Date Field
- Dropdown
- ElasticHeight
- ExpandableCard
- Filter
- FormCheckbox
- Form Control
- Form Label
- HamburgerIcon
- Heading
- Image
- Link
- Loader
- Number Field
- Pagination
- Password
- Phone Field
- Popin
- Portal
- Prose
- Radio Group
- Radio
- Range
- Select
- SidebarLayout
- Spinner
- Switch
- Tabs
- Tag
- TextField
- ValidationMessage
'use client';
import { Radio } from '@/ui/forms/radios/Radio';
import { useState } from 'react';
export function RadioDemo() {
const [selectedValue, setSelectedValue] = useState<string>('');
return (
<div className="flex flex-col gap-8">
<Radio
name="option"
value="option1"
checked={selectedValue === 'option1'}
onChange={(e) => setSelectedValue(e.target.value)}
>
Option 1
</Radio>
<Radio
name="option"
value="option2"
checked={selectedValue === 'option2'}
onChange={(e) => setSelectedValue(e.target.value)}
>
Option 2
</Radio>
<Radio
name="option"
value="option3"
checked={selectedValue === 'option3'}
onChange={(e) => setSelectedValue(e.target.value)}
>
Option 3
</Radio>
</div>
);
}
Installation
npx shadcn@latest add https://develop.trident-ui.pro.clubmed/r/radio.json
Usage
import { Radio } from '@/docs/lib/ui/forms/radios/radio';
import { useState } from 'react';
export function Component() {
const [selectedValue, setSelectedValue] = useState<string>('option1');
return (
<div className="flex flex-col gap-8">
<Radio
name="choice"
value="option1"
checked={selectedValue === 'option1'}
onChange={(e) => setSelectedValue(e.target.value)}
>
Option 1
</Radio>
<Radio
name="choice"
value="option2"
checked={selectedValue === 'option2'}
onChange={(e) => setSelectedValue(e.target.value)}
>
Option 2
</Radio>
<Radio
name="choice"
value="option3"
checked={selectedValue === 'option3'}
onChange={(e) => setSelectedValue(e.target.value)}
>
Option 3
</Radio>
</div>
);
}API Reference
Radio
| Prop | Type | Default | Description |
|---|---|---|---|
name | string | id | The name attribute for the radio input. If not provided, defaults to the generated ID. |
value | string | undefined | The value attribute for the radio input. |
checked | boolean | false | Whether the radio is currently checked. |
onChange | (event: ChangeEvent<HTMLInputElement>) => void | undefined | Native onChange handler. Receives the change event. |
disabled | boolean | false | Whether the radio is disabled. Disabled radios cannot be interacted with and appear in a muted color. |
size | number | 24 | The diameter of the radio button in pixels. |
tabIndex | number | 0 | The tab index for keyboard navigation. |
dataTestId | string | undefined | The data-testid attribute for testing purposes. |
className | string | undefined | Additional CSS classes to apply to the label container. |
children | ReactNode | undefined | The label content to display next to the radio button. |
id | string | auto-generated | The ID attribute for the radio input. Automatically generated if not provided. |
The Radio component also accepts all standard HTML input attributes via InputHTMLAttributes<HTMLInputElement>.
Notes
- Controlled Component: This is a fully controlled component. You must manage the
checkedstate andonChangehandler in the parent component. - Native onChange: Uses standard HTML input onChange behavior. Access the value via
event.target.valueand checked state viaevent.target.checked. - Single Choice Selection: Radio buttons are designed for selecting a single option from a group. Use the same
nameprop for all radios in the same group. - Custom Size: The
sizeprop controls the diameter of the radio button. The inner circle is automatically sized to 2/3 of the specified size. - Disabled State: When disabled, the radio appears in a muted grey color and cannot be interacted with. The onChange callback is not triggered.
- Label Container: The entire component is wrapped in a label element, making the children clickable to toggle the radio.
- Keyboard Support: Supports standard keyboard navigation with customizable tab index.
- Data Attributes: Includes
data-name="Radio"for easy targeting in tests and styling. - Client Component: This component uses React hooks and must be used in a client component (requires "use client" directive in Next.js App Router).
- Saffron Color: The radio button indicator uses the saffron color from the design system (
var(--color-saffron)).