토글
토글 (Toggle)
토글은 켜짐(enabled)과 꺼짐(disabled) 상태를 보거나 전환하는 데 쓰는 컴포넌트예요.
출처: 문서
본문
Toggle 컴포넌트
토글은 켜짐 또는 꺼짐 상태를 보거나 전환하는 데 사용하는 컴포넌트예요.
- Keywords: toggle, switch, on-off, enabled, disabled, state
- Categories: forms-and-input
- Status: general-availability
예시
import Toggle from '@atlaskit/toggle/toggle';
const Examples = (): React.JSX.Element => (
<>
<Toggle label="Basic toggle" />
<Toggle label="Checked toggle" isChecked />
</>
);
export default Examples;
Props
| Prop | Type | Description |
|---|---|---|
defaultChecked |
boolean |
Sets whether the toggle is initially checked or not |
descriptionId |
string |
Use this when you need to provide an extended description about how the toggle works using aria-describedby |
id |
string |
Use a pairing label with your toggle using id and htmlFor props to set the relationship |
isChecked |
boolean |
If defined, it takes precedence over defaultChecked, and the toggle acts as a controlled component |
isDisabled |
boolean |
Sets if the toggle is disabled or not |
isLoading |
boolean |
If defined, it displays a spinner within the toggle |
label |
string |
Text value which will be associated with toggle input using aria-labelledby attribute |
name |
string |
Descriptive name for the value property, to be submitted in a form |
onBlur |
(event: FocusEvent<HTMLInputElement, Element>, analyticsEvent: UIAnalyticsEvent) => void |
Handler to be called when toggle is unfocused |
onChange |
(event: ChangeEvent<HTMLInputElement>, analyticsEvent: UIAnalyticsEvent) => void |
Handler to be called when native 'change' event happens internally |
onFocus |
(event: FocusEvent<HTMLInputElement, Element>, analyticsEvent: UIAnalyticsEvent) => void |
Handler to be called when toggle is focused |
size |
"large" | "regular" |
Toggle size |
value |
string |
Value to be submitted in a form |
사용 지침
- 이진의 켜짐/꺼짐 상태에 사용해요
- 토글의 기능을 설명하는 명확한 라벨을 제공해요
- 적절한 기본 상태를 사용해요
- 즉각적인 상태 변경과 지연된 상태 변경을 고려해요
- 인터페이스 전반에서 일관된 토글 동작을 사용해요
콘텐츠 지침
- 명확하고 설명적인 라벨을 작성해요
- 적절할 때 행동 지향적인(action-oriented) 언어를 사용해요
- 라벨이 토글이 무엇을 제어하는지 명확히 나타내도록 해요
- 토글 간에 일관된 용어를 사용해요
접근성 지침
- 모든 토글에 명확한 라벨을 제공해요
- 토글 상태에 적절한 ARIA 속성을 사용해요
- 키보드 탐색을 지원해요
- 상태 변경에 명확한 시각적 피드백을 제공해요
- 토글의 목적을 설명하는 설명적인 라벨을 사용해요