Your next page is taking shape...

Opening Your Next Page…

Loading the guide and preparing its examples for you to explore. The page will appear here automatically when it’s ready, so you can keep this view open without refreshing.

Made for Preact. Built to be yours.

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 Live Preview
Try it. Make it yours.
Setting the scene...

Interactive preview

Live Preact example Local preview theme · Responsive styles follow the preview widthFull width

Installation

Import RadioGroup and RadioGroupItem from @/components/kamod-ui/radio-group. Label pairs cleanly via id and htmlFor.

Install PackagesTerminal
pnpm add @kamod-ch/ui

Copy 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 SetupTypeScript
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.

src/components/RadioGroupExample.tsx18 lines
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 Live Preview
Try it. Make it yours.
Setting the scene...

Interactive preview

Live Preact example Local preview theme · Responsive styles follow the preview widthFull width

Choice 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 Live Preview
Try it. Make it yours.
Setting the scene...

Interactive preview

Live Preact example Local preview theme · Responsive styles follow the preview widthFull width

Field 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 Live Preview
Try it. Make it yours.
Setting the scene...

Interactive preview

Live Preact example Local preview theme · Responsive styles follow the preview widthFull width

Disabled & 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 Live Preview
Try it. Make it yours.
Setting the scene...

Interactive preview

Live Preact example Local preview theme · Responsive styles follow the preview widthFull width

Inline & 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 Live Preview
Try it. Make it yours.
Setting the scene...

Interactive preview

Live Preact example Local preview theme · Responsive styles follow the preview widthFull width
API reference

Props 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.

API reference
Your API, from source

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

Read each option with its owning component. The
marker identifies required fields verified in that declaration. A ? 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.
@kamod-ch/ui/radio-group7.8 KB min · 2.2 KB gzipSignals: none

RadioGroup

RadioGroupProps

RadioGroup documented props
Prop / typeDescription
children
ComponentChild[] | ComponentChildRadioGroupProps

Configure children for RadioGroup. Compare its accepted type with the Usage Guidance before supplying a value.

Default
—
class
stringRadioGroupProps

Configure class for RadioGroup. Compare its accepted type with the Usage Guidance before supplying a value.

Default
—
defaultValue
stringRadioGroupProps

Configure defaultValue for RadioGroup. Compare its accepted type with the Usage Guidance before supplying a value.

Default
null
name
stringRadioGroupProps

When omitted, a stable unique name is generated (forms can still submit if you add name to inputs manually).

Default
—
onValueChange
((next: string) => void)RadioGroupProps

Configure onValueChange for RadioGroup. Compare its accepted type with the Usage Guidance before supplying a value.

Default
—
required
booleanRadioGroupProps

Configure required for RadioGroup. Compare its accepted type with the Usage Guidance before supplying a value.

Default
false
value
stringRadioGroupProps

Configure value for RadioGroup. Compare its accepted type with the Usage Guidance before supplying a value.

Default
—

RadioGroupItem

RadioGroupItemProps

RadioGroupItem documented props
Prop / typeDescription
children
ComponentChild[] | ComponentChildRadioGroupItemProps

Configure children for RadioGroupItem. Compare its accepted type with the Usage Guidance before supplying a value.

Default
—
class
stringRadioGroupItemProps

Configure class for RadioGroupItem. Compare its accepted type with the Usage Guidance before supplying a value.

Default
—
disabled
boolean | SignalLike<boolean | undefined>RadioGroupItemProps

Configure disabled for RadioGroupItem. Compare its accepted type with the Usage Guidance before supplying a value.

Default
—
onChange
GenericEventHandler<HTMLInputElement>RadioGroupItemProps

Configure onChange for RadioGroupItem. Compare its accepted type with the Usage Guidance before supplying a value.

Default
—
size
"default" | "sm"RadioGroupItemProps

Configure size for RadioGroupItem. Compare its accepted type with the Usage Guidance before supplying a value.

Default
"default"
value
Signalish<string | number | undefined> & stringRadioGroupItemProps

Configure value for RadioGroupItem. Compare its accepted type with the Usage Guidance before supplying a value.

Default
—

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 fields
RadioGroupProps
Exported Source Declaration from RadioGroup.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 fields
RadioGroupItemProps
Exported Source Declaration from RadioGroupItem.tsx. Referenced types retain their original names; inspect that file for imports and supporting definitions. Inspect the Complete Definition of RadioGroupItemProps before adapting it.
Required fields
value

Accessibility

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.

  1. Read the group question and each option name using assistive technology.
  2. Move through options with the keyboard, skip disabled choices and verify a single selected value.
  3. 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.

Take the Next Useful Step

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.