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

Input → TextField 마이그레이션 가이드 (v2 → v3)

원문 보기 위키 갱신

이 문서는 HeroUI의 Input 컴포넌트가 v3에서 어떻게 바뀌었는지를 정리한 마이그레이션 가이드예요. 가장 큰 변화는 Input이 원시(primitive) 컴포넌트로 분리되고, 폼 필드용으로는 TextField가 새로 도입된 점이에요.

출처: HeroUI

본문

참고: 완전한 API 레퍼런스, 스타일링 가이드, 고급 예제는 v3 Input 문서를 참고하세요. 이 가이드는 HeroUI v2에서 마이그레이션하는 데만 집중한 내용이에요.

핵심 변경: Input → TextField

v2: Input은 label, description, 에러 메시지, 검증(validation), 변형, 색상, 크기 등을 내장한 완전한 기능을 갖춘 컴포넌트였어요.

v3: Input은 이제 원시 컴포넌트(그냥 input 요소)예요. 폼 필드가 필요하면 Input을 Label, Description, FieldError 컴포넌트로 감싸는 TextField를 사용하세요. v2에는 별도의 TextField나 InputGroup이 없었고, 단일 Input 컴포넌트가 label, description, 시작/끝 콘텐츠, 검증을 모두 처리했어요.

Input vs TextField 언제 쓸까

TextField 사용 (대부분의 경우)

이런 게 필요할 땐 TextField를 사용하세요.

  • 라벨(Label)
  • 설명(Description)
  • 에러 메시지
  • 검증(Validation)
  • 폼 통합(Form integration)

Input 사용 (원시 컴포넌트만)

이런 게 필요할 땐 Input을 사용하세요.

  • 기본 input 요소만 필요한 경우
  • 커스텀 label/에러 처리
  • 커스텀 폼 컴포넌트와의 통합

구조 변경 (Structure Changes)

v2에서는 Input이 label, description, placeholder 등 각종 요소를 props로 받는 완전한 기능의 컴포넌트였어요.

import { Input } from "@heroui/react";

export default function App() {
  return (
    <Input
      label="Email"
      placeholder="Enter your email"
      type="email"
    />
  );
}

v3에서는 Input이 원시 컴포넌트예요. 라벨과 검증이 있는 폼 필드가 필요하면 Input을 Label, Description, FieldError로 감싸는 TextField를 사용하세요.

import { TextField, Label, Input, FieldError } from "@heroui/react";

export default function App() {
  return (
    <TextField name="email" type="email">
      <Label>Email</Label>
      <Input placeholder="Enter your email" />
      <FieldError />
    </TextField>
  );
}

핵심 변경 사항 (Key Changes)

1. 컴포넌트 분리 (Component Split)

v2: 모든 기능을 갖춘 단일 Input 컴포넌트
v3: Input(원시)과 TextField(컴파운드)로 분리

2. Props 변경 (Prop Changes)

v2 Prop v3 위치 설명
label Label TextField 안에서 Label 컴포넌트 사용
description Description TextField 안에서 Description 컴포넌트 사용
errorMessage FieldError TextField 안에서 FieldError 컴포넌트 사용
variant Input 여러 변형(flat, bordered, underlined, faded)에서 "primary"(기본, 그림자 포함)와 "secondary"(낮은 강조, 그림자 없음, 표면용)로 변경
color, size, radius - 제거됨 (Tailwind CSS 사용)
fullWidth Input 또는 TextField Input과 TextField 모두에서 지원 (fullWidth boolean prop)
labelPlacement - Label로 레이아웃 구성
startContent InputGroup.Prefix TextField 안에서 InputGroup + InputGroup.Prefix 사용
endContent InputGroup.Suffix TextField 안에서 InputGroup + InputGroup.Suffix 사용
isClearable - 버튼으로 직접 구현
isRequired, isInvalid TextField TextField에서 사용
validate TextField TextField에서 validate 사용
classNames - 개별 컴포넌트에 className 사용
onValueChange Input onChange 이벤트 핸들러 사용

마이그레이션 예제 (Migration Examples)

폼 검증 (Form Validation)

{/* With description */}
<Input
  description="We'll never share your email"
  label="Email"
  type="email"
/>

{/* With error message */}
<Input
  errorMessage="Please enter a valid email"
  isInvalid
  label="Email"
  type="email"
/>

{/* Required */}
<Input isRequired label="Email" type="email" />
import { Description } from "@heroui/react";

{/* With description */}
<TextField name="email" type="email">
  <Label>Email</Label>
  <Input />
  <Description>We'll never share your email</Description>
  <FieldError />
</TextField>

{/* With error message */}
<TextField
  isInvalid
  name="email"
  type="email"
  validate={(value) => {
    if (!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(value)) {
      return "Please enter a valid email";
    }
    return null;
  }}
>
  <Label>Email</Label>
  <Input />
  <FieldError />
</TextField>

{/* Required */}
<TextField isRequired name="email" type="email">
  <Label>Email</Label>
  <Input />
  <FieldError />
</TextField>

시작/끝 콘텐츠가 있는 Input (Input with Start/End Content)

접두사 또는 접미사 콘텐츠가 있는 input은 InputGroup 컴파운드 컴포넌트를 사용하세요.

<Input
  label="Price"
  startContent={<span>$</span>}
  type="number"
/>
import { InputGroup } from "@heroui/react";

<TextField name="price" type="number">
  <Label>Price</Label>
  <InputGroup>
    <InputGroup.Prefix>$</InputGroup.Prefix>
    <InputGroup.Input />
  </InputGroup>
  <FieldError />
</TextField>

InputGroup은 접두사/접미사 콘텐츠에 적절한 스타일링과 레이아웃을 제공해요. 이렇게 사용하세요.

  • InputGroup.Prefix — input 앞의 콘텐츠 (startContent 대체)
  • InputGroup.Suffix — input 뒤의 콘텐츠 (endContent 대체)
  • InputGroup.Input — input 요소 자체

클리어 버튼이 있는 Input (Input with Clear Button)

<Input
  isClearable
  label="Email"
  onClear={() => console.log("cleared")}
  type="email"
/>
import { useState } from "react";
import { CloseButton } from "@heroui/react";

const [value, setValue] = useState("");

<TextField name="email" type="email">
  <Label>Email</Label>
  <div className="flex items-center">
    <Input value={value} onChange={(e) => setValue(e.target.value)} />
    {value && (
      <CloseButton
        aria-label="Clear"
        onPress={() => setValue("")}
      />
    )}
  </div>
  <FieldError />
</TextField>

제어된 Input (Controlled Input)

import { useState } from "react";

const [value, setValue] = useState("");

<Input
  label="Email"
  onValueChange={setValue}
  type="email"
  value={value}
/>
import { useState } from "react";

const [value, setValue] = useState("");

<TextField name="email" type="email">
  <Label>Email</Label>
  <Input
    onChange={(e) => setValue(e.target.value)}
    value={value}
  />
  <FieldError />
</TextField>

요약 (Summary)

  1. 컴포넌트 분리: 폼 필드에는 TextField, 원시 input에는 Input을 사용하세요.
  2. Label 필수: label prop 대신 Label 컴포넌트를 사용해야 해요.
  3. 에러 표시: errorMessage prop 대신 FieldError 컴포넌트를 사용해야 해요.
  4. Description: description prop 대신 Description 컴포넌트를 사용해야 해요.
  5. 검증: validate 함수를 Input에서 TextField로 옮기세요.
  6. 시작/끝 콘텐츠: TextField 안에서 InputGroup + InputGroup.Prefix/InputGroup.Suffix를 사용하세요.
  7. 클리어 버튼: CloseButton으로 직접 구현하세요.
  8. 변형 단순화: v2에는 여러 변형(flat, bordered, underlined, faded)이 있었지만, v3에는 "primary"(기본)와 "secondary"(표면용)만 있어요.
  9. 전체 너비: fullWidth prop은 Input과 TextField 모두에서 계속 사용할 수 있어요.
  10. 색상 제거: Tailwind CSS 클래스를 사용하세요.
  11. 크기 제거: Tailwind CSS 클래스를 사용하세요.
  12. Radius 제거: Tailwind CSS 클래스를 사용하세요.
  13. onValueChange 제거: onChange 이벤트 핸들러를 사용하세요.
  14. ClassNames 제거: 개별 컴포넌트에 className prop을 사용하세요.

더 알아보기 (Learn more)