라디오
라디오 (Radio)
라디오는 상호 배타적인 선택지 중에서 하나를 고르는 데 쓰는 컴포넌트예요. 표 안의 옵션처럼 커스텀한 라디오 버튼 표현이 필요하거나 개별 라디오 버튼을 세밀하게 제어해야 할 때 사용해요.
출처: 문서
본문
Radio 컴포넌트
상호 배타적인 선택지 집합에서 하나를 선택하는 라디오 버튼 컴포넌트예요. 표 안의 옵션 같은 커스텀 라디오 버튼 표현이나, 개별 라디오 버튼을 세밀하게 제어해야 할 때 사용해요.
- Keywords: radio, button, input, form, selection, choice, option
- Categories: form
- Status: general-availability
예시
import Radio from '@atlaskit/radio/radio';
export default (): React.JSX.Element => (
<Radio value="option1" label="Option 1" name="choices" onChange={() => console.log('Changed!')} />
);
Props
| Prop | Type | Description |
|---|---|---|
ariaLabel |
string |
The aria-label attribute associated with the radio element |
isChecked |
boolean |
Set the field as checked |
isDisabled |
boolean |
Makes a Radio field unselectable when true |
isInvalid |
boolean |
Marks this as an invalid field |
isRequired |
boolean |
Marks this as a required field |
label |
string | number | boolean | ReactElement<any, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal |
The label value for the input rendered to the DOM |
labelId |
string |
This sets the aria-labelledby attribute |
onChange |
(e: ChangeEvent<HTMLInputElement>, analyticsEvent: UIAnalyticsEvent) => void |
onChange event handler, passed into the props of each Radio Component instantiated within RadioGroup |
value |
string |
Field value |
사용 지침
- 커스텀 라디오 버튼 표현(예: 표 안의 옵션)에 사용해요
- 개별 라디오 버튼을 세밀하게 제어해야 할 때 사용해요
- 옵션을 논리적인 순서로 나열해요(가능성이 높은 것부터 낮은 것까지)
- 하나의 옵션을 기본값으로 설정해요(가장 안전하고 보안성이 높은 옵션)
- 선택되지 않은 상태가 필요하면 'None' 옵션을 추가해요
- 모든 옵션을 나열할 수 없으면 'Other' 옵션을 추가해요
콘텐츠 지침
- 맥락을 제공하는 명확하고 설명적인 라벨을 사용해요
- 라벨을 간결하되 유익하게 유지해요
- 라벨에 sentence case를 사용해요
- 숫자 선택지가 겹치거나 건너뛰지 않도록 해요
접근성 지침
- 필수 또는 유효하지 않은 라디오 필드에 오류 메시지를 포함해요
- 결제, 개인정보, 보안 관련 위험도가 높은 옵션을 미리 선택하지 마세요
- 탭 순서에 유지해야 한다면 disabled 라디오 버튼을 사용하지 마세요
- 더 나은 접근성을 위해 disabled 상태 대신 검증(validation)을 사용해요
RadioGroup 컴포넌트
하나의 선택지만 선택할 수 있는 옵션 목록을 보여주는 라디오 그룹 컴포넌트예요. 상호 배타적인 옵션의 단순한 목록을 원하는 대부분의 라디오 버튼 상황에서 사용해요.
- Keywords: radio, group, form, selection, choice, options, list
- Categories: form
- Status: general-availability
예시
import RadioGroup from '@atlaskit/radio/radio-group';
// Radio group with options
const options = [
{ name: 'color', value: 'red', label: 'Red' },
{ name: 'color', value: 'blue', label: 'Blue' },
];
export default (): React.JSX.Element => {
const [value, setValue] = React.useState('red');
return (
<RadioGroup options={options} value={value} onChange={(e) => setValue(e.currentTarget.value)} />
);
};
Props
| Prop | Type | Description |
|---|---|---|
defaultValue |
string |
Sets the initial selected value on the RadioGroup |
id |
string |
|
isDisabled |
boolean |
Sets the disabled state of all Radio elements in the group |
isInvalid |
boolean |
Sets the invalid state of all Radio elements in the group |
isRequired |
boolean |
Sets the required state of all Radio elements in the group |
labelId |
string |
This sets the aria-labelledby attribute |
name |
string |
Sets the name prop on each of the Radio elements in the group |
onChange |
(e: React.ChangeEvent<HTMLInputElement>, analyticsEvent: UIAnalyticsEvent) => void |
Function that gets after each change event |
onInvalid |
(event: React.SyntheticEvent<any, Event>) => void |
Function that gets fired after each invalid event |
options |
OptionPropType[] |
An array of objects, each object is mapped onto a Radio element within the group (required) |
value |
string |
Once set, controls the selected value on the RadioGroup |
사용 지침
- 단순한 옵션 목록이 있는 대부분의 라디오 버튼 상황에 사용해요
- 옵션을 논리적인 순서로 나열해요(가능성이 높은 것부터 낮은 것까지)
- 하나의 옵션을 기본값으로 설정해요(가장 안전하고 보안성이 높은 옵션)
- 선택되지 않은 상태가 필요하면 'None' 옵션을 추가해요
- 모든 옵션을 나열할 수 없으면 'Other' 옵션을 추가해요
- 더 긴 옵션 목록에는 select 컴포넌트를 사용해요
콘텐츠 지침
- 맥락을 제공하는 명확하고 설명적인 라벨을 사용해요
- 라벨을 간결하되 유익하게 유지해요
- 라벨에 sentence case를 사용해요
- 숫자 선택지가 겹치거나 건너뛰지 않도록 해요
접근성 지침
- 필수 또는 유효하지 않은 라디오 필드에 오류 메시지를 포함해요
- 결제, 개인정보, 보안 관련 위험도가 높은 옵션을 미리 선택하지 마세요
- 탭 순서에 유지해야 한다면 disabled 라디오 버튼을 사용하지 마세요
- 더 나은 접근성을 위해 disabled 상태 대신 검증(validation)을 사용해요
- 화살표 키로 올바른 키보드 탐색을 보장해요