Forms & Input
Radio Group
A set of mutually exclusive options styled like modern radio controls. Make the expected input clear before someone interacts, and keep the current value, help text and validation feedback connected. Import it from @/components/kamod-ui/radio-group.
Source · Design reference · API reference · Theming · Styles
Interactive preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthInstallation
Import RadioGroup and RadioGroupItem from @/components/kamod-ui/radio-group. Label pairs cleanly via id and htmlFor.
pnpm add @kamod-ch/uiCopy an example with @kamod-ch/ui or the matching @kamod-ch/ui/… subpath. The code block switches between those two installs. Connect The Global Theme CSS and Tailwind Source Detection before your first render.
Usage
Use defaultValue for uncontrolled groups, or value with onValueChange when the parent owns state. Omit name to get a stable generated group name. Pair each item with Label for accessible names; use size="sm" for dense layouts. disabled and aria-invalid on items match form and validation patterns.
import { RadioGroup } from "@kamod-ch/ui";Choose a complete composition from the examples below; required child components and props vary by pattern.
Component Examples & Variants
Explore Radio Group in Different Contexts, from the starting pattern to the compositions below. Begin with Default, then compare the examples that match your content, state and layout. These are working patterns to adapt, not a list of interchangeable variant values: check the API Reference before using a prop or combining behaviors. Look at the surrounding labels, supporting text and spacing as well as the component itself.
Read the Result and Its Implementation Together. Use each showcase’s Code view to inspect imports and composition, or its Prompt view to prepare a setup or adaptation brief. Try the narrow preview and local theme controls before connecting real data, and use Reset to return an example to its initial state. Keep layout changes in class utilities where appropriate; follow the Component Styles Guide for hierarchy and the Theming Guide for shared surfaces and colors. The Accessibility Notes explain what to preserve when making those changes.
Default
Ask One Question with Several Exclusive Answers. Place each RadioGroup option beside a visible label to present one choice among alternatives. The selected value answers the shared question, while the labels make the consequence of each available option understandable.
Keep a visible label for every control, choose an initial selection deliberately, and avoid using radios for independent settings that users may enable in combination.
import { Label, RadioGroup, RadioGroupItem } from "@kamod-ch/ui";
export const Example = () => (
<RadioGroup defaultValue="option-one" class="grid gap-3">
<div class="flex items-center gap-3">
<RadioGroupItem value="option-one" id="rg-option-one" />
<Label size="sm" htmlFor="rg-option-one">
Option one
</Label>
</div>
<div class="flex items-center gap-3">
<RadioGroupItem value="option-two" id="rg-option-two" />
<Label size="sm" htmlFor="rg-option-two">
Option two
</Label>
</div>
</RadioGroup>
);Description
Explain the Tradeoff between Choices. Give each radio choice a short title and a secondary explanation when the options need more context. The extra line helps readers compare consequences without turning the primary label into a dense block of text.
Keep the primary option name concise and associate the supporting text with the relevant control, so the added context remains available beyond the visual layout.
Interactive preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthChoice Card
Give Complex Choices More Room to Breathe. Use a card-like label surface around each radio option when the choice includes supporting details. The larger presentation helps comparison, while the radio group still allows one selected value for the shared question.
Use a concise option title with the details needed to compare it against its neighbors. Test label activation across the whole surface, and keep secondary links or actions from competing with the radio choice.
Interactive preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthField Group
Name the Collection before the Individual Answers. Use FieldSet and field content to introduce the radio group's heading and description before listing its options. This gives the collection a shared purpose while each radio retains its own individual label.
Keep group-level validation close to the options and preserve the underlying radio relationships when rearranging the layout or adding richer labels.
Interactive preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthDisabled & Invalid
Distinguish Unavailable Choices from a Missing Answer. Disable unavailable radio options and expose invalid selection through aria-invalid when needed. Keep the explanation adjacent to the group so users can distinguish an unavailable choice from a correctable validation problem.
Add text describing the constraint and recovery, and avoid relying on a similar muted treatment for both situations.
Interactive preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthInline & Small
Use a Compact Row for Short, Familiar Options. Arrange concise radio choices horizontally with compact indicators when they fit a toolbar-like setting. Preserve a clear group label and enough room for translated text before choosing this denser layout.
Let the choices wrap or stack before their labels become cramped. Test activation through both the indicator and its text, and retain a visible focus treatment when the group sits among other toolbar controls.
Interactive preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthProps and Data
Configure Radio Group using the contracts below. Read the documented options alongside the Source Definitions to understand which values your application supplies and which details the component owns. Start with a prop or helper, then follow its type link to inspect the declaration without leaving the page.
Props, slots and variants for this component.
Type cards are extracted from this checkout’s TypeScript source at build time. Props inherited through HTMLAttributes, Omit or variant helpers remain references in those declarations; their fields are not flattened here. Match the reference to your installed version, and check a package’s exports before writing an import type. A type exported by a source file is not necessarily re-exported by @kamod-ch/ui.
Component Props
? means a field can be omitted; it does not promise a fallback value. Existing documented defaults remain alongside the descriptions. For callbacks, check the argument and return types before connecting your own state or services.RadioGroup
RadioGroupProps
| Prop / type | Description |
|---|---|
children | Configure
|
class | Configure
|
defaultValue | Configure
|
name | When omitted, a stable unique name is generated (forms can still submit if you add name to inputs manually).
|
onValueChange | Configure
|
required | Configure
|
value | Configure
|
RadioGroupItem
RadioGroupItemProps
| Prop / type | Description |
|---|---|
children | Configure
|
class | Configure
|
disabled | Configure
|
onChange | Configure
|
size | Configure
|
value | Configure
|
Data Type Reference
Expand a card to inspect and copy the exact declaration. The code header identifies its repository file; follow imported or inherited types in the Implementation Source when you need the complete dependency chain. Required-field summaries cover fields declared directly in that type. Source-only helpers and inferred schema outputs describe the local implementation, not additional props you can pass to every component.
RadioGroup Props
7 declared fieldsRadioGroupPropsRadioGroup.tsx. Referenced types retain their original names; inspect that file for imports and supporting definitions. Inspect the Complete Definition of RadioGroupProps before adapting it.RadioGroupItem Props
3 declared fieldsRadioGroupItemPropsRadioGroupItem.tsx. Referenced types retain their original names; inspect that file for imports and supporting definitions. Inspect the Complete Definition of RadioGroupItemProps before adapting it.valueAccessibility
Build the Complete Interaction, Including the Parts Outside Radio Group. The notes below distinguish the current implementation from the labels, content and behavior your application supplies. Start with the Live Preview, check the Props and Data Reference, and test the finished composition with real content rather than assuming that an unchanged visual example covers every use case.
Built-in Behavior and Defaults
RadioGroup exposes role="radiogroup"; its items contain native radio inputs sharing the group's name. RadioGroupItem wraps its input and children in a label, so meaningful option text participates in the input's name.
Labels and Relationships
Give the group an overall question using aria-labelledby or aria-label, then name each option distinctly. Keep descriptions of trade-offs visible. Use unique group names for unrelated questions so browser-native radio navigation does not join them accidentally.
Keyboard and Focus
Native radio behavior handles selection within the same named set. Test Tab entry and arrow-key movement in supported browsers. Use the group's value callback for controlled state so the visible selection and the checked input agree.
States and Integration Details
Avoid nesting additional buttons or links inside an option's label. Explain unavailable options outside the disabled control, and distinguish no selection from a valid option whose value happens to be an empty string.
Verify the Complete Interaction
Check Behavior as Well as Markup. Work through these scenarios in the application where the component will be used. Automated checks can help find structural problems; also review the reading experience with a screen reader, keyboard focus and the actual feedback from your application.
- Read the group question and each option name using assistive technology.
- Move through options with the keyboard, skip disabled choices and verify a single selected value.
- Render two unrelated groups and ensure their selection and keyboard behavior remain independent.
Recheck the result after changing Theme Tokens, translations or class overrides. Include text enlargement, narrow layouts and reduced-motion settings where animation is present. Inspect the Component Source when a behavior differs from your expectation; a role or state attribute does not implement keyboard interaction by itself.
For background, read the WAI-ARIA Authoring Guidance and Keyboard Interface Guidance. These explain the patterns; verify browser and assistive-technology behavior for the implementation and audience you actually support.
You have the pieces. Put them into one real interaction, keep its state in one place, and check the result with the content your application will actually show.
Connect the Foundation
Return to Choose and Compose Components to connect this reference to a working screen. Keep global CSS in one entrypoint and import only the components that screen needs.
Build the Surrounding Screen
Find a neighboring interaction in the Component Library, or start with a complete Block. Replace sample content and destinations before refining the layout; a local class change can stay with the composition.
Make the Result Hold Up
Use shared theme roles for changes that belong everywhere. Then review the whole journey: keyboard focus, long labels, narrow screens and a clear way to recover when something fails.
Keep a link to the source and note your intentional changes. Your next edit should begin with a clear decision, not another search.