# Radio Group
URL: /lynx/components/radio-group
Source: https://github.com/daangn/seed-design/blob/dev/docs/content/lynx/components/radio-group.mdx
A radio group component that allows users to select only one option among several.
Lynx Engine 최소 버전: 3.6
사용 가능 버전: @seed-design/lynx-react@0.1.0, @seed-design/lynx-css@0.1.0
## Preview
```tsx
import "./styles";
import { VStack, useSeedClassName } from "@seed-design/lynx-react";
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
return (
);
}
```
## Installation
- npm: npx @seed-design/cli add ui:radio-group
- pnpm: pnpm dlx @seed-design/cli add ui:radio-group
- yarn: yarn dlx @seed-design/cli add ui:radio-group
- bun: bun x @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`.
```tsx
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
export function ContactMethod() {
return (
);
}
```
If `invalid` is `true` and `errorMessage` exists, the error message is displayed instead of `description` on screen.
## Props
### `RadioGroup`
### `RadioGroupItem`
### `Radiomark`
## 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
```tsx
import "./styles";
import { VStack, useSeedClassName } from "@seed-design/lynx-react";
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
return (
);
}
```
### Tones
#### Brand
```tsx
import "./styles";
import { VStack, useSeedClassName } from "@seed-design/lynx-react";
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
return (
);
}
```
#### Neutral
```tsx
import "./styles";
import { VStack, useSeedClassName } from "@seed-design/lynx-react";
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
return (
);
}
```
### 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.
```tsx
import "./styles";
import { useState } from "@lynx-js/react";
import { VStack, useSeedClassName } from "@seed-design/lynx-react";
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
const [value, setValue] = useState("regular");
return (
);
}
```
### 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.
```tsx
import "./styles";
import { useState } from "@lynx-js/react";
import { VStack, useSeedClassName } from "@seed-design/lynx-react";
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
const longLabel =
"Consequat ut veniam aliqua deserunt occaecat enim occaecat veniam et et cillum nulla officia incididunt incididunt. Sint laboris labore occaecat fugiat culpa voluptate ullamco in elit dolore exercitation nulla.";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
const [value, setValue] = useState("medium");
return (
);
}
```
### Disabled
`RadioGroup`'s `disabled` disables the entire group. Individual `RadioGroupItem`s can also be disabled separately.
```tsx
import "./styles";
import { VStack, useSeedClassName } from "@seed-design/lynx-react";
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
return (
);
}
```
### Listening to Value Changes
You can detect selection value changes with `RadioGroup`'s `onValueChange`. In Controlled mode, use `value` and `onValueChange` together.
```tsx
import "./styles";
import { useState } from "@lynx-js/react";
import { VStack, useSeedClassName } from "@seed-design/lynx-react";
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
const [count, setCount] = useState(0);
const [lastValue, setLastValue] = useState(null);
return (
{
setCount((previous) => previous + 1);
setLastValue(value);
}}
>
onValueChange called: {count} times, last value: {lastValue ?? "-"}
);
}
```
### 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`.
```tsx
import "./styles";
import {
HStack,
RadioGroup as RadioGroupPrimitive,
VStack,
useSeedClassName,
} from "@seed-design/lynx-react";
import { RadioGroup, Radiomark } from "@/components/ui/radio-group";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
return (
regularmediumbold
);
}
```
### RadioGroupField Integration
You can use RadioGroupField-related props such as `label`, `description`, `errorMessage`.
```tsx
import "./styles";
import { useState } from "@lynx-js/react";
import { ActionButton, HStack, VStack, useSeedClassName } from "@seed-design/lynx-react";
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
const [contact, setContact] = useState("email");
const [firstErrorMessage, setFirstErrorMessage] = useState();
const [option, setOption] = useState("option1");
const [secondErrorMessage, setSecondErrorMessage] = useState();
const handleFirstSubmit = () => {
setFirstErrorMessage(contact === "email" ? "이메일은 선택할 수 없습니다." : undefined);
};
const handleSecondSubmit = () => {
setSecondErrorMessage(option === "option1" ? "옵션 1은 선택할 수 없습니다." : undefined);
};
return (
제출
제출
);
}
```
## 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 `` dot. To pass custom icons, install `@karrotmarket/lynx-monochrome-icon` separately and use monochrome icon components. Direct `
Custom icon packages are not included in the Registry default installation.
```sh
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
| Feature | Web equivalent | Description |
| --------------------------- | ---------------------- | --------------------------------------------------------------------- |
| React Hook Form | HTML form library | Replace with `value`, `onValueChange`, and app-level submission logic |
| `RadioGroupItemHiddenInput` | `` | Lynx does not have HTML form submission model |
| `name` | native form field name | Lynx does not have native form submission model |
| `focus` / `focusVisible` | Keyboard focus | Lynx has no keyboard focus concept |
| `onChange` (raw DOM event) | `React.ChangeEvent` | Meaningless. Replace with `onValueChange` |