Radio
The Radio component is used for selecting a single option from a list. It supports dynamic label and error slots, and can be grouped using RadioGroup.
사용 시기
- 여러 옵션에서 단일 상태를 선택하는 데 사용됩니다.
- Select와의 차이점은 Radio가 사용자에게 표시되어 선택의 비교를 용이하게 할 수 있다는 것입니다. 즉, 너무 많지 않아야 합니다.
Example Usage
astro
<Radio id="radio1" label="Standard Radio" />
<Radio id="radio2" checked label="Selected by Default" /> Radio Groups & Deselection
Use the RadioGroup component to manage layouts and grouping. You can enable canDeselect to allow users to uncheck a selected radio option.
astro
<RadioGroup name="rg-demo" canDeselect>
<Radio id="rg1" label="Option 1" name="rg-demo" />
<Radio id="rg2" label="Option 2" name="rg-demo" />
<Radio id="rg3" label="Option 3" name="rg-demo" />
</RadioGroup> States
astro
<Radio id="radio-disabled" label="Disabled Option" disabled />
<Radio id="radio-disabled-checked" label="Disabled Selected Option" disabled checked />
<Radio id="radio-error" label="Error Option" variant="error" error="This field is required" /> Horizontal Layout
astro
<RadioGroup name="rg-horizontal" orientation="horizontal">
<Radio id="rgh1" label="Daily" name="rg-horizontal" />
<Radio id="rgh2" label="Weekly" name="rg-horizontal" />
<Radio id="rgh3" label="Monthly" name="rg-horizontal" />
</RadioGroup> Slots
You can fully customize the label and error messages using the default slot and error slot.
astro
<Radio id="radio-slots">
<span class="font-bold">Pro Plan</span> - $10/mo
<span slot="error" class="text-xs">You must select a plan to continue</span>
</Radio> How to Use
astro
---
import Radio from '@/components/data-entry/Radio.astro';
import RadioGroup from '@/components/data-entry/RadioGroup.astro';
---
<RadioGroup name="options">
<Radio id="opt1" label="Option 1" name="options" />
<Radio id="opt2" label="Option 2" name="options" />
</RadioGroup> API
| 속성 | 설명 | 타입 | 기본값 |
|---|---|---|---|
| label | 라디오 버튼의 레이블 텍스트 | string | |
| name | 라디오 버튼을 그룹화하기 위한 이름 속성 | string | |
| error | Indicates an error state or displays an error message | string | boolean | |
| success | Indicates a success state or displays a success message | string | boolean | |
| disabled | Disables the component | boolean | false |