Skip to content
Klarhimmel UI

Radio group

Breakfast
npx shadcn add @klarhimmel/radio-group

Examples

  • Basic

  • States

  • Form

DetailsAbout, usage, props and more

One choice from a few options that are all visible. Built on native radio inputs.

When to use

  • Use for

    Two to five mutually exclusive options that are better seen together.

  • Not for

    Many options. Use Select. Independent yes/no choices. Use Checkbox.

  • Pairs with

    Field, Button, forms.

Preview

Breakfast

Delivered between 07:30 and 09:30

Chosen: buffet

radio-group.tsx
import { Theme } from '@/components/klarhimmel/theme/style';
import { RadioGroup, Radio } from '@/components/klarhimmel/ui/radio-group';

export default function Example() {
  return (
    <Theme theme="brand">
      <RadioGroup legend="Breakfast" name="meal" defaultValue="buffet">
        <Radio value="buffet" label="Buffet" />
        <Radio value="tray" label="Tray to the room" />
      </RadioGroup>
    </Theme>
  );
}

Import

Import

import { RadioGroup, Radio } from '@/components/klarhimmel/ui/radio-group';
Files
radio-group.tsx, in components/klarhimmel/ui/. With it: theme, utils.
Render in
Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.

Props

PropTypeDefaultDescription
RadioGroup.legendReactNoderequiredRequired: the question the options answer. It names the group for assistive tech.
RadioGroup.namestring-The form field name. Radios sharing a name are one group to the browser.
RadioGroup.valuestring-Controlled or uncontrolled state.
RadioGroup.defaultValuestring-Controlled or uncontrolled state.
RadioGroup.onValueChange(value: string) => void-Controlled or uncontrolled state.
RadioGroup.disabledboolean-Helper or error text, error styling, switch the group off.
RadioGroup.invalidboolean-Helper or error text, error styling, switch the group off.
RadioGroup.hintReactNode-Helper or error text, error styling, switch the group off.
RadioGroup.classNamestring-Extra classes, merged after the component's own.
RadioGroup.childrenReactNoderequired
Radio.valuestringrequiredControlled or uncontrolled state.
Radio.labelReactNoderequiredValue and label are required; the hint sits under the label.
Radio.hintReactNode-Helper or error text, error styling, switch the group off.
native attributesInputHTMLAttributes-Every native attribute of the element passes through, className included.

Accessibility

KeyDoes
Tab / Shift+TabEnters and leaves the group as one stop, landing on the chosen option
Down / RightMoves to the next option and selects it, wrapping
Up / LeftMoves to the previous option and selects it, wrapping
SpaceSelects the focused option

Native radio inputs: the browser provides the keys and the form value, also without script.

Accessibility