인풋
선택적 라벨과 오류 메시지를 가진 단일 행 손그림 스타일의 텍스트 필드입니다.
개요
데이터를 수집하기 위한 단일 행 텍스트 필드로, 선택적 보이는 라벨과(React에서) 오류 메시지를 가져요.
구조
손그림 외곽선의 텍스트 박스 위에 선택적 라벨; React에서는 error가 설정되면 박스 아래에 role="alert" 요소로 오류 메시지가 렌더돼요.
변형 및 상태
| State | Status | Notes |
|---|---|---|
| 기본 | Implemented | — |
| 포커스 | Implemented | 외곽선 색상이 포커스 토큰으로 바뀌어요. |
| 비활성화 | Implemented | — |
| 오류 / 무효 | Implemented | React 전용 — aria-invalid + aria-describedby + role="alert". Web Components나 React Native에는 구현되지 않았어요. |
| 로딩 | Not implemented | — |
Web Components는 대신 required(ElementInternals를 통한 네이티브 제약 검증)를 가져요 — React와 React Native는 그걸 prop으로 노출하지 않아요. 이는 문서 누락이 아니라 두 개의 별개 실제 간극이에요: Web Components나 React Native에 대한 오류 데모를 보여주지 마세요.
사용법
Do
- 오류는 항상 구체적이고 행동 가능한 메시지와 짝지으세요("Please enter at least 8 characters."), "Invalid input." 같은 일반적인 메시지가 아니에요.
- 플레이스홀더 텍스트에만 의존하지 말고 라벨을 보이게 유지하세요.
Don't
- 플레이스홀더 텍스트를 유일한 접근성 이름으로 사용하지 마세요 — 사용자가 입력하면 사라져요.
- 필드당 두 개 이상의 오류 메시지를 표시하지 마세요.
접근성
- React:
aria-invalid+aria-describedby(오류<span role="alert">를 가리킴) + RadixLabel/htmlFor연결. - Web Components:
label/for연결; 라벨이 없으면aria-label이 플레이스홀더로 폴백해요. 현재 무효 상태 ARIA는 없어요. - React Native:
accessibilityLabel이placeholder로 폴백;accessibilityState={{disabled}}는 오류/무효 개념이 없어요. - 일반적인 관례는 접근성 가이드를 참고하세요.
콘텐츠
라벨은 수집하는 데이터를 나타내요(“Email”, “Password”), 동작이 아니에요 — 라벨이 동작을 나타내는 Button과 대조돼요. 오류 메시지는 무엇이 잘못되었고 어떻게 고치는지 말해줘요.
Props API
React@ghds/react
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | — | Radix Label로 연결된 보이는 라벨. |
error | string | — | 오류 메시지. 설정 시 필드를 무효로 표시하고 알려줘요. |
disabled | boolean | false | 편집을 비활성화해요. |
...rest | InputHTMLAttributes | — | 다른 모든 네이티브 <input> 속성(value, onChange 등)이 전달돼요. |
Web Components@ghds/web-components
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | '' | 현재 필드 값, 폼 값으로 미러링돼요. |
name | string | — | 제출되는 컨트롤 이름. |
type | 'text' | 'email' | 'password' | 'search' | 'tel' | 'url' | 'number' | 'text' | 입력 모드. |
placeholder | string | — | 플레이스홀더 텍스트. |
label | string | — | 선택적 보이는 라벨이자 접근성 이름. |
disabled | boolean | false | 편집과 폼 참여를 비활성화해요. |
required | boolean | false | 네이티브 제약 검증. error prop은 없어요. |
React Native@ghds/react-native
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | — | 제어 방식의 텍스트 값. |
onChangeText | (text: string) => void | — | 변경 핸들러. |
placeholder | string | — | 플레이스홀더; 기본 a11y 라벨이기도 해요. |
disabled | boolean | false | 편집을 비활성화해요. |
accessibilityLabel | string | — | 플레이스홀더로 폴백해요. |
keyboardType | TextInputProps['keyboardType'] | — | 키보드 변형. |
secureTextEntry | boolean | — | 비밀번호 입력을 가려요. error prop은 없어요. |
testID | string | — | 쿼리용 테스트 핸들. |
코드 예시
// React — @ghds/react (onChange는 이벤트를 받아요. `error`는 React에만 있어요)
import { Input } from '@ghds/react/input';
<Input
label="Email"
placeholder="you@example.com"
value={email}
onChange={(event) => setEmail(event.target.value)}
/>;
<Input label="Password" type="password" error="Please enter at least 8 characters." />;
<!-- Web Components — @ghds/web-components (`required`는 있지만 `error`나 invalid prop은 없어요) -->
<script type="module">
import '@ghds/web-components/input';
</script>
<gh-input label="Email" placeholder="you@example.com" type="email"></gh-input>
<gh-input label="Username" required></gh-input>
// React Native — @ghds/react-native (onChangeText는 문자열 값을 그대로 받아요. `error` prop은 없어요)
import { Input } from '@ghds/react-native/input';
<Input
value={email}
onChangeText={setEmail}
placeholder="you@example.com"
keyboardType="email-address"
/>;
라이브 데모
React 데모에는 오류 상태가 포함돼요; Web Components 데모는 의도적으로 포함하지 않아요(error prop이 없음) 대신 required를 보여줘요.