Getting Started
Components
- Accordion
- Advanced Toast
- AlertMessage
- ArrowButton
- Arrows
- Avatar
- Backdrop
- Basic Toast
- Breadcrumb
- Button
- CardBackground
- Card
- Carousel
- Chapters
- ChatBody
- ChatButton
- ChatHeader
- ChatInput
- ChatMessageActions
- ChatMessageEditor
- ChatMessage
- ChatTypingIndicator
- ChatWindowCsatPrompt
- ChatWindowQuote
- ChatWindow
- CheckboxSelect
- Checkbox
- Checkboxes
- Chip
- ChoiceExpander
- Clickable
- ContentReview
- Countdown
- CriteriaDates
- CriteriaParticipants
- CriteriaTransports
- Date Field
- Datepicker
- Dropdown
- ElasticHeight
- ExpandableCard
- ExpandableText
- Filter
- FloatingLabelTextField
- Form Control
- Form Label
- Frame
- HamburgerIcon
- Heading
- Image
- JourneyCard
- LayerHeader
- Layer
- Link
- Loader
- Number Field
- PageNavigation
- Pagination
- Paragraph
- Password
- Phone Field
- Popin
- Portal
- ProductThumbnail
- Promises
- Prose
- Radio Group
- RadioSelect
- Radio
- Range
- Scrollbar
- Select
- SidebarLayout
- SliderFrame
- SparkleWrapper
- Spinner
- Switch
- Table
- Tabs
- Tag
- TextField
- Toggle
- Tooltip
- 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={(_, value) => setSelectedValue(value)}
>
Option 1
</Radio>
<Radio
name="option"
value="option2"
checked={selectedValue === 'option2'}
onChange={(_, value) => setSelectedValue(value)}
>
Option 2
</Radio>
<Radio
name="option"
value="option3"
checked={selectedValue === 'option3'}
onChange={(_, value) => setSelectedValue(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={(_, value) => setSelectedValue(value)}
>
Option 1
</Radio>
<Radio
name="choice"
value="option2"
checked={selectedValue === 'option2'}
onChange={(_, value) => setSelectedValue(value)}
>
Option 2
</Radio>
<Radio
name="choice"
value="option3"
checked={selectedValue === 'option3'}
onChange={(_, value) => setSelectedValue(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: Event, value: string) => void | undefined | Change handler receiving browser event, selected value. |
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. - Normalized onChange: Uses the shared forms contract
onChange(event, value)for consistency across form components. - 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)).