입력 그룹 (Input Group)
InputGroup 컴포넌트는 Prefix, Input, Suffix를 조합해 입력 필드에 앞/뒤 콘텐츠를 붙여주는 복합(compound) 컴포넌트예요. 접두어나 접미어의 너비를 자동으로 측정해 Input의 패딩에 적용해 주므로 배치가 매우 편리해요.
출처: 문서
본문
Import
import { InputGroup } from 'heroui-native';
Anatomy
<InputGroup>
<InputGroup.Prefix>...</InputGroup.Prefix>
<InputGroup.Input />
<InputGroup.Suffix>...</InputGroup.Suffix>
</InputGroup>
- InputGroup: Prefix, Input, Suffix를 감싸는 레이아웃 컨테이너예요. 애니메이션 설정과 측정 컨텍스트를 제공해서 Prefix/Suffix 너비가 Input의 패딩으로 자동 적용돼요.
- InputGroup.Prefix: Input 왼쪽에 고정 배치되는 절대 위치 View예요. 측정된 너비가 InputGroup.Input의
paddingLeft로 자동 적용돼요. - InputGroup.Suffix: Input 오른쪽에 고정 배치되는 절대 위치 View예요. 측정된 너비가 InputGroup.Input의
paddingRight로 자동 적용돼요. - InputGroup.Input: Input 컴포넌트로의 통과(pass-through)예요. 모든 Input props를 그대로 받아요. 측정된 Prefix/Suffix에서
paddingLeft/paddingRight를 자동으로 받아요.
Usage
기본 사용법 (Basic Usage)
InputGroup 컴포넌트는 복합 파트를 사용해 입력 필드에 접두어/접미어 콘텐츠를 붙여요.
<InputGroup>
<InputGroup.Prefix>...</InputGroup.Prefix>
<InputGroup.Input placeholder="Enter text" />
<InputGroup.Suffix>...</InputGroup.Suffix>
</InputGroup>
Prefix만 사용 (With Prefix Only)
아이콘 같은 앞쪽 콘텐츠를 입력 필드에 붙여요.
<InputGroup>
<InputGroup.Prefix isDecorative>
<PersonIcon size={16} />
</InputGroup.Prefix>
<InputGroup.Input placeholder="Username" />
</InputGroup>
Suffix만 사용 (With Suffix Only)
아이콘 같은 뒤쪽 콘텐츠를 입력 필드에 붙여요.
<InputGroup>
<InputGroup.Input placeholder="Search products..." />
<InputGroup.Suffix isDecorative>
<MagnifierIcon size={16} />
</InputGroup.Suffix>
</InputGroup>
장식 vs 상호작용 (Decorative vs Interactive)
Prefix 또는 Suffix에 isDecorative를 설정하면 터치가 Input으로 통과하도록 하고, 스크린 리더에서 콘텐츠를 숨겨요. 데코레이터에 상호작용 요소가 포함되어 있다면 이 속성을 생략해요.
<InputGroup>
<InputGroup.Prefix isDecorative>
<LockIcon size={16} />
</InputGroup.Prefix>
<InputGroup.Input placeholder="Enter your password" secureTextEntry />
<InputGroup.Suffix>
<Pressable onPress={togglePasswordVisibility}>
<EyeIcon size={16} />
</Pressable>
</InputGroup.Suffix>
</InputGroup>
비활성화 상태 (Disabled State)
전체 입력 그룹을 비활성화해요. 비활성화 상태는 모든 자식 컴포넌트에 전파됩니다.
<InputGroup isDisabled>
<InputGroup.Prefix isDecorative>
<LockIcon size={16} />
</InputGroup.Prefix>
<InputGroup.Input placeholder="Disabled input" />
</InputGroup>
TextField 통합 (With TextField Integration)
TextField, Label, Description과 결합해 완전한 폼 필드를 지원해요.
<TextField isRequired>
<Label>Email</Label>
<InputGroup>
<InputGroup.Prefix isDecorative>
<MailIcon size={16} />
</InputGroup.Prefix>
<InputGroup.Input placeholder="you@example.com" keyboardType="email-address" />
</InputGroup>
<Description>We'll never share your email</Description>
</TextField>
Example
import { InputGroup } from 'heroui-native';
import { Ionicons } from '@expo/vector-icons';
import { useState } from 'react';
import { Pressable, View } from 'react-native';
export default function InputGroupExample() {
const [value, setValue] = useState('');
const [isPasswordVisible, setIsPasswordVisible] = useState(false);
return (
<View className="px-5">
<InputGroup>
<InputGroup.Prefix isDecorative>
<Ionicons name="lock-closed-outline" size={16} color="#888" />
</InputGroup.Prefix>
<InputGroup.Input
value={value}
onChangeText={setValue}
placeholder="Enter your password"
secureTextEntry={!isPasswordVisible}
/>
<InputGroup.Suffix>
<Pressable
onPress={() => setIsPasswordVisible(!isPasswordVisible)}
hitSlop={20}
>
<Ionicons
name={isPasswordVisible ? 'eye-off-outline' : 'eye-outline'}
size={16}
color="#888"
/>
</Pressable>
</InputGroup.Suffix>
</InputGroup>
</View>
);
}
더 많은 예시는 GitHub 저장소에서 찾을 수 있어요.
API Reference
InputGroup
| prop | type | default | description |
|---|---|---|---|
children |
React.ReactNode |
- | 입력 그룹 안에 렌더링할 자식 요소 |
className |
string |
- | 추가 CSS 클래스 |
isDisabled |
boolean |
false |
전체 입력 그룹과 그 자식이 비활성화되었는지 여부 |
animation |
AnimationRootDisableAll |
- | 입력 그룹의 애니메이션 구성 |
...ViewProps |
ViewProps |
- | 모든 표준 React Native View props 지원 |
AnimationRootDisableAll
InputGroup 루트 컴포넌트의 애니메이션 구성이에요. 값으로는:
"disable-all": 자식을 포함한 모든 애니메이션 비활성화 (전파됨)undefined: 기본 애니메이션 사용
InputGroup.Prefix
| prop | type | default | description |
|---|---|---|---|
children |
React.ReactNode |
- | prefix 안에 렌더링할 콘텐츠 |
className |
string |
- | 추가 CSS 클래스 |
isDecorative |
boolean |
false |
true면 터치가 Input으로 통과하고 스크린 리더에서 콘텐츠가 숨겨짐 |
...ViewProps |
ViewProps |
- | 모든 표준 React Native View props 지원 |
InputGroup.Suffix
| prop | type | default | description |
|---|---|---|---|
children |
React.ReactNode |
- | suffix 안에 렌더링할 콘텐츠 |
className |
string |
- | 추가 CSS 클래스 |
isDecorative |
boolean |
false |
true면 터치가 Input으로 통과하고 스크린 리더에서 콘텐츠가 숨겨짐 |
...ViewProps |
ViewProps |
- | 모든 표준 React Native View props 지원 |
InputGroup.Input
Input 컴포넌트로의 통과(pass-through)예요. 모든 Input props를 그대로 받아요.