Lynx

Radio Group

A radio group component that allows users to select only one option among several.

Engine ≥ 3.6
Available since@seed-design/lynx-react@0.1.0, @seed-design/lynx-css@0.1.0
Loading Lynx example…

Installation

npx @seed-design/cli add ui:radio-group

Usage

RadioGroup displays field guidance information along with the selection state. You can use label, labelWeight, indicator, showRequiredIndicator, description, errorMessage.

import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";

export function ContactMethod() {
  return (
    <RadioGroup
      label="Preferred contact method"
      indicator="Required"
      description="Please select how you would like to be contacted."
      defaultValue="chat"
    >
      <RadioGroupItem value="chat" label="Chat" />
      <RadioGroupItem value="phone" label="Phone" />
    </RadioGroup>
  );
}

If invalid is true and errorMessage exists, the error message is displayed instead of description on screen.

Props

RadioGroup

Prop

Type

label?React.ReactNode
indicator?React.ReactNode
showRequiredIndicator?boolean | undefined
description?React.ReactNode
errorMessage?React.ReactNode
value?string | undefined
defaultValue?string | undefined
onValueChange?((value: string) => void) | undefined
style?CSSProperties | undefined
children?React.ReactNode
className?string | undefined
required?boolean | undefined
readOnly?boolean | undefined

RadioGroupItem

Prop

Type

label?React.ReactNode
valuestring
disabled?boolean | undefined
style?CSSProperties | undefined
children?React.ReactNode
className?string | undefined

Radiomark

Prop

Type

className?string | undefined
style?CSSProperties | undefined

Accessibility

RadioGroup is an accessibility element by default and uses accessibility-role-description="radiogroup". If the group is disabled, it also passes accessibility-traits="disabled". If you pass a string label to Registry RadioGroup, the same content is also connected to accessibility-label.

RadioGroupItem uses accessibility-role-description="radio" by default. The selection state is passed as selected or not selected in accessibility-value, and the disabled state is passed as accessibility-traits="disabled".

If you use a string label, the Registry wrapper connects that value to the item's accessibility-label. When you put non-string content in label or compose the compound API directly, explicitly specify accessibility-label for each item. If needed, you can override all default accessibility props directly.

Examples

Sizes

Loading Lynx example…

Tones

Brand

Loading Lynx example…

Neutral

Loading Lynx example…

Weights

Unlike React's per-item weight, Lynx's weight is a group-level prop. The example below divides groups by weight. The two groups share the same control value, so only one of the two items can be selected.

Loading Lynx example…

Long Label

Lynx's size is also a group-level prop. The example below divides groups by size. The two groups share the same control value, so only one of the two items can be selected.

Loading Lynx example…

Disabled

RadioGroup's disabled disables the entire group. Individual RadioGroupItems can also be disabled separately.

Loading Lynx example…

Listening to Value Changes

You can detect selection value changes with RadioGroup's onValueChange. In Controlled mode, use value and onValueChange together.

Loading Lynx example…

Use Cases

React Hook Form

React Hook Form assumes HTML forms and input, so the same example cannot be executed on Lynx. On Lynx, control the selection value with value and onValueChange. Handle submission and validation in app state management and request flow.

Using Radiomark

Using Registry's Radiomark and the compound API of @seed-design/lynx-react together, you can share the selection state while changing the item layout. Radiomark can only be used inside RadioGroup.Item.

Loading Lynx example…

RadioGroupField Integration

You can use RadioGroupField-related props such as label, description, errorMessage.

Loading Lynx example…

Scale Feedback

Lynx RadioGroupItem changes the background color of Radiomark while being pressed. Since it does not reduce size like React, the --seed-radiomark-feedback-scale CSS variable is also not used.

Differences from Web Version

Lynx RadioGroup has the following differences from React RadioGroup.

  • Error message rendering: React keeps description in the accessibility tree when error is displayed, but Lynx has no visually hidden handling method in the DOM, so it renders only errorMessage and excludes description from screen and accessibility tree.
  • Icon rendering method: The default RadioGroup.ItemIndicator renders as a <view> dot. To pass custom icons, install @karrotmarket/lynx-monochrome-icon separately and use monochrome icon components. Direct <svg> injection is not supported in Lynx.
  • Event handling: Exposes only onValueChange(value: string) instead of onChange. Tap handlers are owned inside the item.
  • Pressed state: Instead of size reduction on the web, internal press state changes the background color of Radiomark.
  • Rendering elements: Renders native <view> / <text> elements instead of HTML <label> / <input type="radio">.
  • Strict containment: RadioGroupItem, Radiomark, RadioGroup.ItemControl, RadioGroup.ItemIndicator, RadioGroup.ItemLabel must be used within the appropriate context of RadioGroup.Root and RadioGroup.Item. Radiomark is not a standalone primitive but a snippet helper that wraps ItemControl and ItemIndicator within item context.

Custom icon packages are not included in the Registry default installation.

bun add @karrotmarket/lynx-monochrome-icon@^1.20.0

Unsupported Lynx Features

The following features are currently not supported due to Lynx platform constraints.

Excluded due to runtime model differences

FeatureWeb equivalentDescription
React Hook FormHTML form libraryReplace with value, onValueChange, and app-level submission logic
RadioGroupItemHiddenInput<input type="radio">Lynx does not have HTML form submission model
namenative form field nameLynx does not have native form submission model
focus / focusVisibleKeyboard focusLynx has no keyboard focus concept
onChange (raw DOM event)React.ChangeEventMeaningless. Replace with onValueChange

Table of contents