본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Input (Input)

원문 보기 위키 갱신

Input은 사용자 입력을 받는 스타일된 테두리와 배경을 가진 텍스트 입력 컴포넌트예요. 단독으로도 쓸 수 있고, TextField 컴포넌트 안에서 완전한 폼 구조를 만들 때도 잘 어울려요. variant, 검증 상태, 커스텀 스타일링까지 폼 개발에 필요한 기능을 갖추고 있답니다.

출처: 문서

본문

Import

import { Input } from 'heroui-native';

Usage

기본 사용법

Input은 단독으로 또는 TextField 컴포넌트 안에서 사용할 수 있어요.

import { Input } from 'heroui-native';

<Input placeholder="Enter your email" />;

TextField 안에서

Input은 TextField와 함께 사용하면 완전한 폼 구조를 만들 수 있어요.

import { Input, Label, TextField } from 'heroui-native';

<TextField>
  <Label>Email</Label>
  <Input placeholder="Enter your email" />
</TextField>;

검증과 함께 (With Validation)

입력이 invalid일 때 오류 상태를 표시할 수 있어요.

import { FieldError, Input, Label, TextField } from 'heroui-native';

<TextField isRequired isInvalid={true}>
  <Label>Email</Label>
  <Input placeholder="Enter your email" />
  <FieldError>Please enter a valid email</FieldError>
</TextField>;

로컬 invalid 상태 오버라이드

컨텍스트의 invalid 상태를 입력에 대해 오버라이드할 수 있어요.

import { FieldError, Input, Label, TextField } from 'heroui-native';

<TextField isInvalid={true}>
  <Label isInvalid={false}>Email</Label>
  <Input placeholder="Enter your email" isInvalid={false} />
  <FieldError>Email format is incorrect</FieldError>
</TextField>;

비활성 상태 (Disabled State)

상호작용을 막으려면 입력을 비활성화할 수 있어요.

import { Input, Label, TextField } from 'heroui-native';

<TextField isDisabled>
  <Label>Disabled Field</Label>
  <Input placeholder="Cannot edit" value="Read only value" />
</TextField>;

Variant 사용

컨텍스트에 따라 입력 스타일을 지정하는 다른 variant를 사용할 수 있어요.

import { Input, Label, TextField } from 'heroui-native';

<TextField>
  <Label>Primary Variant</Label>
  <Input placeholder="Primary style" variant="primary" />
</TextField>

<TextField>
  <Label>Secondary Variant</Label>
  <Input placeholder="Secondary style" variant="secondary" />
</TextField>

커스텀 스타일링

className을 사용해 입력 외형을 커스터마이즈할 수 있어요.

import { Input, Label, TextField } from 'heroui-native';

<TextField>
  <Label>Custom Styled</Label>
  <Input
    placeholder="Custom colors"
    className="bg-blue-50 border-blue-500 focus:border-blue-700"
  />
</TextField>;

Bottom Sheet 안에서

BottomSheet 안에 Input을 렌더링할 때는 useBottomSheetAwareHandlers 훅으로 키보드 회피 핸들러를 연결하세요. 반환되는 onFocus와 onBlur를 Input에 전달하면 돼요.

Note: useBottomSheetAwareHandlers는 BottomSheet 안에서 사용해야 해요. BottomSheet.Content 안에 렌더링된 자식 컴포넌트에서 호출하세요. BottomSheet 컨텍스트 밖에서 반환되는 핸들러는 no-op이에요.

import { Input, TextField, useBottomSheetAwareHandlers } from 'heroui-native';

const BottomSheetTextInput = () => {
  const { onFocus, onBlur } = useBottomSheetAwareHandlers();

  return (
    <TextField>
      <Input
        placeholder="Type here..."
        onFocus={onFocus}
        onBlur={onBlur}
      />
    </TextField>
  );
};

Example

import { Ionicons } from '@expo/vector-icons';
import { Description, Input, Label, TextField } from 'heroui-native';
import { useState } from 'react';
import { Pressable, View } from 'react-native';
import { withUniwind } from 'uniwind';

const StyledIonicons = withUniwind(Ionicons);

export const TextInputContent = () => {
  const [email, setEmail] = useState('');
  const [password, setPassword] = useState('');
  const [isPasswordVisible, setIsPasswordVisible] = useState(false);

  return (
    <View className="gap-4">
      <TextField isRequired>
        <Label>Email</Label>
        <Input
          placeholder="Enter your email"
          keyboardType="email-address"
          autoCapitalize="none"
          value={email}
          onChangeText={setEmail}
        />
        <Description>
          We'll never share your email with anyone else.
        </Description>
      </TextField>

      <TextField isRequired>
        <Label>New password</Label>
        <View className="w-full flex-row items-center">
          <Input
            value={password}
            onChangeText={setPassword}
            className="flex-1 px-10"
            placeholder="Enter your password"
            secureTextEntry={!isPasswordVisible}
          />
          <StyledIonicons
            name="lock-closed-outline"
            size={16}
            className="absolute left-3.5 text-muted"
            pointerEvents="none"
          />
          <Pressable
            className="absolute right-4"
            onPress={() => setIsPasswordVisible(!isPasswordVisible)}
          >
            <StyledIonicons
              name={isPasswordVisible ? 'eye-off-outline' : 'eye-outline'}
              size={16}
              className="text-muted"
            />
          </Pressable>
        </View>
        <Description>Password must be at least 6 characters</Description>
      </TextField>
    </View>
  );
};

더 많은 예시는 GitHub 저장소에서 찾을 수 있어요.

API Reference

Input

prop type default description
isInvalid boolean undefined 입력이 invalid 상태인지(컨텍스트 오버라이드) 여부
variant 'primary' | 'secondary' 'primary' 입력용 variant 스타일
className string - 입력의 커스텀 클래스 이름
selectionColorClassName string "accent-accent" 선택 색상용 커스텀 className
placeholderColorClassName string "field-placeholder" placeholder 텍스트 색상용 커스텀 className
isBottomSheetAware boolean true BottomSheet 안에서 렌더링될 때 입력이 키보드 상태를 자동으로 처리하는지. false로 설정해 비활성화
animation AnimationRoot undefined 입력용 애니메이션 구성
background React.ReactNode - 텍스트 입력 뒤의 배경 레이어. undefined는 활성 테마가 기본 배경 콘텐츠를 등록했을 때 테마 인식 기본값을 렌더링(대체 색상은 variant를 따름: primary → field token, secondary → default token), 커스텀 노드는 교체, null은 제거
...TextInputProps TextInputProps - 모든 표준 React Native TextInput props 지원

Note: TextField 컴포넌트 안에서 사용하면 Input은 form-item-state 컨텍스트를 통해 TextField의 폼 상태(isDisabled, isInvalid)를 자동으로 소비해요.

Input.Background

텍스트 입력 뒤에 렌더링되는 absolute-fill 컨테이너예요. children이 없으면 활성 라이브러리 테마가 기본 콘텐츠(예: glass 블러 레이어)를 결정하고, children을 전달하면 동일한 위치 지정과 클리핑으로 커스텀 콘텐츠를 호스팅할 수 있어요.

prop type default description
children React.ReactNode - 배경 컨테이너 내부의 커스텀 콘텐츠
className string - 추가 CSS 클래스
fallbackColor ThemeColor 'field' 네이티브 블러가 없는 플랫폼(Android / web)에서 불투명 대체색으로 사용되는 테마 색상 토큰
...ViewProps ViewProps - 모든 표준 View props 지원

더 알아보기 (Learn more)