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

TextArea (텍스트 영역)

원문 보기 위키 갱신

TextArea는 표준 HTML 속성을 받아들이는 다중 줄 텍스트 입력 프리미티브 컴포넌트예요. 해요체로 쉽게 설명드릴게요.

출처: HeroUI TextArea

본문

사용법 (Usage)

import { TextArea } from '@heroui/react';
{"name": "textarea-basic"}

검증, 라벨, 오류 메시지에 대해서는 **TextField**를 참고해요.

예시 (Examples)

변형 (Variants)

TextArea 컴포넌트는 두 가지 시각적 변형을 지원해요:

  • primary (기본값) - 그림자가 있는 표준 스타일, 대부분의 사용 사례에 적합
  • secondary - 그림자가 없는 낮은 강조 변형, Surface 컴포넌트에서 사용하기 적합
{"name": "textarea-variants"}

Surface 안에서 (In Surface)

Surface 컴포넌트 안에서 사용할 때는 variant="secondary"를 사용해 surface 배경에 적합한 낮은 강조 변형을 적용해요.

{"name": "textarea-on-surface"}

전체 너비 (Full Width)

{"name": "textarea-full-width"}

제어된 상태 (Controlled)

{"name": "textarea-controlled"}

행과 크기 조절 (Rows and Resizing)

{"name": "textarea-rows"}

커스터마이징 (Customization)

Tailwind CSS

{"name": "text-area-custom-styles"}

Global CSS

공유 .textarea 클래스를 Tailwind의 @layer components로 한 번 재정의해요.

@layer components {
  .textarea {
    @apply rounded-xl border border-border bg-surface px-4 py-3 text-sm leading-6 shadow-sm;

    &:hover,
    &[data-hovered="true"] {
      @apply bg-surface-secondary border-border/80;
    }

    &:focus-visible,
    &[data-focus-visible="true"] {
      @apply border-accent ring-2 ring-accent/20;
    }

    &[data-invalid="true"] {
      @apply border-danger bg-danger-soft text-danger;
    }
  }
}

스타일링 참고 (Styling Reference)

HeroUI는 BEM 방법론을 따라 컴포넌트 변형과 상태를 재사용하고 쉽게 커스터마이징할 수 있게 해요.

CSS 클래스 (CSS Classes)

기본 클래스 [!toc]

  • .textarea – 기본 <textarea> 요소 스타일

상호작용 상태 (Interactive States)

  • 호버 (Hover): :hover 또는 [data-hovered="true"]
  • 포커스 표시 (Focus Visible): :focus-visible 또는 [data-focus-visible="true"]
  • 무효 (Invalid): [data-invalid="true"]
  • 비활성화 (Disabled): :disabled 또는 [aria-disabled="true"]

API 참고 (API Reference)

TextArea

TextArea는 모든 표준 HTML <textarea> 속성과 다음을 추가로 받아들여요:

Prop Type Default Description
className string - Tailwind classes merged with the base styles.
rows number 3 Number of visible text lines.
cols number - Visible width of the text control.
value string - Controlled value for the textarea.
defaultValue string - Initial uncontrolled value.
onChange (event: React.ChangeEvent<HTMLTextAreaElement>) => void - Change handler.
placeholder string - Placeholder text.
disabled boolean false Disables the textarea.
readOnly boolean false Makes the textarea read-only.
required boolean false Marks the textarea as required.
name string - Name for form submission.
autoComplete string - Autocomplete hint for the browser.
maxLength number - Maximum number of characters.
minLength number - Minimum number of characters.
wrap 'soft' | 'hard' - How text wraps when submitted.
fullWidth boolean false Whether the textarea should take full width of its container
variant "primary" | "secondary" "primary" Visual variant of the component. primary is the default style with shadow. secondary is a lower emphasis variant without shadow, suitable for use in surfaces.

isInvalid, isRequired 같은 검증 props와 오류 처리는 **TextField**를 TextArea의 자식 컴포넌트로 사용해요.

더 알아보기 (Learn more)