RadioGroup Component

The RadioGroup component is a fully accessible and highly customizable selection control built with TypeScript and Tailwind CSS. It allows users to select a single option from a list with full keyboard navigation, rich content support, and complete styling flexibility.

Use selectedValue and onChange for controlled state, orientation for layout direction, and size for consistent scaling. You can also enhance options with icon and description for better UX clarity.

Option Structure

Pass an options array with string labels and values. Descriptions, icons, and per-option disabled states are optional.

ts
1type RadioOption = {
2  label: string;
3  value: string;
4  description?: string;
5  icon?: React.ReactNode;
6  disabled?: boolean;
7};

Import Component From Library

javascript
1import { RadioGroup } from "@neuctra/ui";

Basic Usage Code

Start with a simple radio group. The component supports single selection with keyboard navigation, icons, and descriptions.

jsx
1import { useState } from 'react';
2import { RadioGroup } from '@neuctra/ui';
3
4function BasicExample() {
5  const [value, setValue] = useState('option1');
6
7  const options = [
8    { label: 'Option One', value: 'option1' },
9    { label: 'Option Two', value: 'option2' },
10    { label: 'Option Three', value: 'option3' }
11  ];
12
13  return (
14    <RadioGroup
15      name="example"
16      options={options}
17      selectedValue={value}
18      onChange={setValue}
19    />
20  );
21}

What It Does

Single Selection: Only one option can be selected at a time.
Keyboard Navigation: Arrow keys, Home/End, Space/Enter support.
Multiple Sizes: Small, medium, and large variants.
Flexible Layout: Vertical or horizontal orientation.
Rich Content: Support for icons, descriptions, and custom styling.
Fully Accessible: ARIA attributes, screen reader support, focus management.

Basic Usage

Create a simple radio group with options array. Each option needs a label and value.

Rich Content Support

Add icons and descriptions to make options more informative and visually appealing.

Sizes

Choose from three size variants: sm, md (default), and lg.

Small (sm)

Medium (md) - Default

Large (lg)

Orientation

Display options vertically (default) or horizontally using the orientation prop.

Vertical (default)

Horizontal

States & Validation

Handle disabled options, read-only mode, required fields, and error states.

Please select an option

Keyboard Navigation

Full keyboard support for accessibility and power users.

Navigation:
  • ↑ ↓ Move up/down
  • ← → Move left/right
  • Home First option
  • End Last option
Selection:
  • Space Select focused option
  • Enter Select focused option
  • Tab Move to next focusable element

Styling & Customization

RadioGroup supports multiple styling layers so you can fully customize layout, structure, and selection state using Tailwind CSS classes.

Props Table

All available props for the RadioGroup component.

PropTypeDefaultDescription
namestring—Form field name for native radio grouping.
optionsOption[]requiredList of radio options (label, value, description, icon, disabled).
selectedValuestring—Currently selected option value.
onChange(value: string) => void—Triggered when selection changes.
disabledbooleanfalseDisables all options.
readOnlybooleanfalsePrevents interaction but keeps UI active.
requiredbooleanfalseMarks field as required for forms.
errorstring—Error message below component.
size"sm" | "md" | "lg""md"Controls radio size.
orientation"vertical" | "horizontal""vertical"Layout direction.
animationDurationnumber0.2Dot animation speed in seconds.
classNamestring—Root container styles.
itemClassNamestring—Each radio item wrapper.
labelClassNamestring—Label text styling.
descriptionClassNamestring—Description text styling.
iconWrapperClassNamestring—Icon container styling.
indicatorClassNamestring—Outer radio circle styling.
dotClassNamestring—Inner selected dot styling.
errorClassNamestring—Error message styling.
styleReact.CSSProperties—Root inline styles.
itemStyleReact.CSSProperties—Item inline styles.
labelStyleReact.CSSProperties—Label inline styles.
descriptionStyleReact.CSSProperties—Description inline styles.
iconWrapperStyleReact.CSSProperties—Icon wrapper inline styles.
indicatorStyleReact.CSSProperties—Radio indicator inline styles.
dotStyleReact.CSSProperties—Dot inline styles.
errorStyleReact.CSSProperties—Error message inline styles.

Common Mistakes

<RadioGroup selectedValue="one" />

options array is required.

<RadioGroup selectedValue="one" />

Without onChange, selection will not update.

<RadioGroup label="Choose one" />

RadioGroup does not have a group label prop. Render your own label text above the component when needed.

<RadioGroup options={options} selectedValue={value} onChange={setValue} />

Proper controlled usage.

Pro Tips

  • Use orientation="horizontal" for ratings, pricing, or quick choices.
  • Add icon + description to improve decision clarity.
  • Keep selectedValue controlled for predictable UI state.
  • Use readOnly instead of disabling for preview modes.
  • Use keyboard navigation — it's already built in (Arrow keys, Enter, Space).
  • Prefer Tailwind via className props instead of inline styles for scalability.
  • Skip disabled options automatically — no extra logic needed.

Frequently Asked Questions

How do I install and import the RadioGroup component?

Install the @neuctra/ui package, then import it with: import { RadioGroup } from "@neuctra/ui";

What variants and sizes does RadioGroup support?

RadioGroup supports sizes: sm, md, lg. Use the variant and size props to switch between them, or pass a className to layer on custom Tailwind CSS classes.

Is the RadioGroup component accessible?

RadioGroup is built with semantic HTML and standard ARIA attributes, and supports keyboard navigation and focus states out of the box, so it works well with screen readers and keyboard-only users.

Built with React, Tailwind CSS & TypeScript.