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

Vue Textarea (텍스트에어리어) 컴포넌트

원문 보기 위키 갱신

Textarea는 표준 textarea 엘리먼트에 스타일링과 autoResize 기능을 더해 주는 컴포넌트예요. 몇 줄이든 자유롭게 늘어나는 여러 줄 입력 칸이 필요할 때 쓰는 기본 폼 요소라고 보면 돼요.

출처: 문서

본문

가져오기 (Import)

가장 기본이 되는 가져오기부터 볼게요. PrimeVue에서 Textarea를 가져오는 방법은 다음과 같아요.

import Textarea from 'primevue/textarea';

접근성 (Accessibility)

스크린 리더 관점에서 Textarea 컴포넌트는 전달된 prop을 암묵적으로 그대로 포함하는 네이티브 textarea 엘리먼트로 렌더링돼요. 컴포넌트를 설명하는 값은 label 태그를 id prop과 조합해 제공하거나, aria-labelledby, aria-label props를 직접 사용해 제공할 수 있어요.

키보드 지원

키 기능
tab 입력 칸으로 포커스를 옮겨요.
<label for="address1">Address 1</label>
<Textarea id="address1" />

<span id="address2">Address 2</span>
<Textarea aria-labelledby="address2" />

<Textarea aria-label="Address Details" />

자동 높이 조절 (AutoResize)

autoResize를 켜면 스크롤바를 보여 주는 대신 textarea가 입력 내용에 맞춰 늘어나요.

<Textarea v-model="value" autoResize rows="5" cols="30" />
Composition API Example
<template>
    <div class="card flex justify-center">
        <Textarea v-model="value" autoResize rows="5" cols="30" />
    </div>
</template>

<script setup>
import { ref } from 'vue';

const value = ref('');
<\/script>

기본 (Basic)

Textarea는 v-model prop으로 양방향 값 바인딩을 해요.

<Textarea v-model="value" rows="5" cols="30" />

비활성화 (Disabled)

disabled가 있으면 엘리먼트를 편집하거나 포커스할 수 없어요.

<Textarea v-model="value" rows="5" cols="30" disabled />
Composition API Example
<template>
    <div class="card flex justify-center">
        <Textarea v-model="value" rows="5" cols="30" disabled />
    </div>
</template>

<script setup>
import { ref } from 'vue';

const value = ref('Disabled');
<\/script>

채우기 (Filled)

variant 속성을 filled로 지정하면 기본 outlined 스타일보다 시각적 강조가 더 강한 모습으로 컴포넌트가 표시돼요.

<Textarea v-model="value" variant="filled" rows="5" cols="30" />
Composition API Example
<template>
    <div class="card flex justify-center">
        <Textarea v-model="value" variant="filled" rows="5" cols="30" />
    </div>
</template>

<script setup>
import { ref } from 'vue';

const value = ref('');
<\/script>

플로트 라벨 (Float Label)

포커스를 받으면 입력 필드 위에 플로팅 라벨이 나타나요. 자세한 내용은 FloatLabel 문서를 참고하세요.

<FloatLabel>
    <Textarea id="over_label" v-model="value1" rows="5" cols="30" style="resize: none" />
    <label for="over_label">Over Label</label>
</FloatLabel>

<FloatLabel variant="in">
    <Textarea id="in_label" v-model="value2" rows="5" cols="30" style="resize: none" />
    <label for="in_label">In Label</label>
</FloatLabel>

<FloatLabel variant="on">
    <Textarea id="on_label" v-model="value3" rows="5" cols="30" style="resize: none" />
    <label for="on_label">On Label</label>
</FloatLabel>
Composition API Example
<template>
    <div class="card flex flex-wrap justify-center items-end gap-4">
        <FloatLabel>
            <Textarea id="over_label" v-model="value1" rows="5" cols="30" style="resize: none" />
            <label for="over_label">Over Label</label>
        </FloatLabel>

        <FloatLabel variant="in">
            <Textarea id="in_label" v-model="value2" rows="5" cols="30" style="resize: none" />
            <label for="in_label">In Label</label>
        </FloatLabel>

        <FloatLabel variant="on">
            <Textarea id="on_label" v-model="value3" rows="5" cols="30" style="resize: none" />
            <label for="on_label">On Label</label>
        </FloatLabel>
    </div>
</template>

<script setup>
import { ref } from 'vue';

const value1 = ref('');
const value2 = ref('');
const value3 = ref('');
<\/script>

플루이드 (Fluid)

fluid prop을 true로 설정하면 컴포넌트가 컨테이너의 전체 너비를 차지해요.

<Textarea v-model="value" rows="5" fluid />
Composition API Example
<template>
    <div class="card">
        <Textarea v-model="value" rows="5" fluid />
    </div>
</template>

<script setup>
import { ref } from 'vue';

const value = ref('');
<\/script>

폼 (Forms)

Textarea는 PrimeVue Forms 라이브러리와 매끄럽게 통합돼요.

<Form v-slot="$form" :resolver="resolver" :initialValues="initialValues" @submit="onFormSubmit" class="flex flex-col gap-4">
    <div class="flex flex-col gap-1">
        <Textarea name="address" rows="5" cols="30" style="resize: none" />
        <Message v-if="$form.address?.invalid" severity="error" size="small" variant="simple">{{ $form.address.error?.message }}</Message>
    </div>
    <Button type="submit" severity="secondary" label="Submit" />
</Form>
Composition API Example
<template>
    <div class="card flex justify-center">
        <Form v-slot="$form" :resolver="resolver" :initialValues="initialValues" @submit="onFormSubmit" class="flex flex-col gap-4">
            <div class="flex flex-col gap-1">
                <Textarea name="address" rows="5" cols="30" style="resize: none" />
                <Message v-if="$form.address?.invalid" severity="error" size="small" variant="simple">{{ $form.address.error?.message }}</Message>
            </div>
            <Button type="submit" severity="secondary" label="Submit" />
        </Form>
    </div>
</template>

<script setup>
import { ref } from 'vue';
import { zodResolver } from '@primevue/forms/resolvers/zod';
import { useToast } from "primevue/usetoast";
import { z } from 'zod';

const toast = useToast();
const initialValues = ref({
    address: ''
});
const resolver = ref(zodResolver(
    z.object({
        address: z.string().min(1, { message: 'Address is required.' })
    })
));

const onFormSubmit = ({ valid }) => {
    if (valid) {
        toast.add({ severity: 'success', summary: 'Form is submitted.', life: 3000 });
    }
};
<\/script>

이프타 라벨 (Ifta Label)

IftaLabel은 필드 안쪽에 상단 정렬된 라벨을 만들 때 사용해요. 자세한 내용은 IftaLabel 문서를 참고하세요.

<IftaLabel>
    <Textarea id="description" v-model="value" rows="5" cols="30" style="resize: none" />
    <label for="description">Description</label>
</IftaLabel>
Composition API Example
<template>
    <div class="card flex justify-center">
        <IftaLabel>
            <Textarea id="description" v-model="value" rows="5" cols="30" style="resize: none" />
            <label for="description">Description</label>
        </IftaLabel>
    </div>
</template>

<script setup>
import { ref } from 'vue';

const value = ref(null);
<\/script>

유효하지 않은 상태 (Invalid)

invalid prop을 사용하면 검증 실패를 알리는 invalid 상태가 표시돼요. 폼 검증 라이브러리와 통합할 때 이 스타일을 활용할 수 있어요.

<Textarea v-model="value" rows="5" cols="30" :invalid="!value" style="resize: none" placeholder="Address" />
Composition API Example
<template>
    <div class="card flex justify-center">
        <Textarea v-model="value" rows="5" cols="30" :invalid="!value" style="resize: none" placeholder="Address" />
    </div>
</template>

<script setup>
import { ref } from 'vue';

const value = ref('');
<\/script>

크기 (Sizes)

Textarea는 기본 크기 외에 small과 large 크기를 제공해요.

<Textarea v-model="value1" size="small" placeholder="Small" rows="3" />
<Textarea v-model="value2" placeholder="Normal" rows="3" />
<Textarea v-model="value3" size="large" placeholder="Large" rows="3" />
Composition API Example
<template>
    <div class="card flex flex-col items-center gap-4">
        <Textarea v-model="value1" size="small" placeholder="Small" rows="3" />
        <Textarea v-model="value2" placeholder="Normal" rows="3" />
        <Textarea v-model="value3" size="large" placeholder="Large" rows="3" />
    </div>
</template>

<script setup>
import { ref } from 'vue';

const value1 = ref(null);
const value2 = ref(null);
const value3 = ref(null);
<\/script>

Textarea

Props

아래는 Textarea가 받는 props 목록이에요. 앞쪽 절반은 DOM에 그대로 전달되는 aria 속성과 네이티브 속성들이고, 뒤쪽에서 modelValue, autoResize 같은 컴포넌트 고유 props가 나와요.

이름 타입 기본값 설명
aria-activedescendant string - 복합 위젯, 텍스트박스, 그룹, 애플리케이션에 DOM 포커스가 있을 때 현재 활성 엘리먼트를 식별해요.
aria-atomic Booleanish - aria-relevant 속성이 정의한 변경 알림을 기준으로 보조 기술이 변경된 영역 전체를 보여 줄지, 일부만 보여 줄지 나타내요.
aria-autocomplete "none" | "inline" | "list" | "both" - 텍스트 입력이 사용자가 의도한 값에 대한 하나 이상의 예측을 표시할 수 있는지 나타내고, 예측이 만들어질 경우 어떻게 제시할지 지정해요.
aria-busy Booleanish - 엘리먼트가 수정 중이며, 보조 기술이 사용자에게 노출하기 전에 수정이 끝나기를 기다릴 수 있음을 나타내요.
aria-checked Booleanish | "mixed" - 체크박스, 라디오 버튼 등 위젯의 현재 "checked" 상태를 나타내요.
aria-colcount Numberish - 테이블, 그리드, 트리그리드의 전체 컬럼 수를 정의해요.
aria-colindex Numberish - 테이블, 그리드, 트리그리드의 전체 컬럼 수를 기준으로 엘리먼트의 컬럼 인덱스나 위치를 정의해요.
aria-colspan Numberish - 테이블, 그리드, 트리그리드에서 셀이나 그리드셀이 차지하는 컬럼 수를 정의해요.
aria-controls string - 현재 엘리먼트가 내용이나 존재를 제어하는 엘리먼트(들)를 식별해요.
aria-current Booleanish | "page" | "step" | "location" | "date" | "time" - 컨테이너나 관련 엘리먼트 집합 안에서 현재 항목을 나타내는 엘리먼트를 가리켜요.
aria-describedby string - 객체를 설명하는 엘리먼트(들)를 식별해요.
aria-details string - 객체에 대한 상세하고 확장된 설명을 제공하는 엘리먼트를 식별해요.
aria-disabled Booleanish - 엘리먼트가 인지 가능하지만 비활성화되어 편집하거나 조작할 수 없음을 나타내요.
aria-dropeffect "link" | "none" | "copy" | "execute" | "move" | "popup" - 드래그한 객체를 드롭 대상에 놓았을 때 수행할 수 있는 기능을 나타내요.
aria-errormessage string - 객체에 대한 오류 메시지를 제공하는 엘리먼트를 식별해요.
aria-expanded Booleanish - 엘리먼트나 그 엘리먼트가 제어하는 다른 그룹 엘리먼트가 현재 펼쳐졌는지 접혀 있는지 나타내요.
aria-flowto string - 사용자가 선택하면 보조 기술이 문서 소스 순서의 일반적인 기본 읽기 방식을 재정의할 수 있도록, 대체 읽기 순서에서 다음 엘리먼트(들)를 식별해요.
aria-grabbed Booleanish - 드래그 앤 드롭 동작에서 엘리먼트의 "grabbed" 상태를 나타내요.
aria-haspopup Booleanish | "menu" | "listbox" | "tree" | "grid" | "dialog" - 엘리먼트가 트리거할 수 있는 메뉴나 대화상자 같은 대화형 팝업의 종류와 제공 여부를 나타내요.
aria-hidden Booleanish - 엘리먼트가 접근성 API에 노출되는지 여부를 나타내요.
aria-invalid Booleanish | "grammar" | "spelling" - 입력된 값이 애플리케이션이 기대하는 형식에 맞지 않음을 나타내요.
aria-keyshortcuts string - 엘리먼트를 활성화하거나 포커스를 주기 위해 작성자가 구현한 키보드 단축키를 나타내요.
aria-label string - 현재 엘리먼트에 라벨을 붙이는 문자열 값을 정의해요.
aria-labelledby string - 현재 엘리먼트에 라벨을 붙이는 엘리먼트(들)를 식별해요.
aria-level Numberish - 구조 안에서 엘리먼트의 계층 수준을 정의해요.
aria-live "off" | "assertive" | "polite" - 엘리먼트가 갱신될 것임을 나타내고, 라이브 영역에서 사용자 에이전트·보조 기술·사용자가 기대할 수 있는 갱신 유형을 설명해요.
aria-modal Booleanish - 엘리먼트가 표시될 때 모달인지 여부를 나타내요.
aria-multiline Booleanish - 텍스트박스가 여러 줄 입력을 받는지 한 줄만 받는지 나타내요.
aria-multiselectable Booleanish - 현재 선택 가능한 하위 항목에서 사용자가 둘 이상을 선택할 수 있음을 나타내요.
aria-orientation "horizontal" | "vertical" - 엘리먼트의 방향이 가로인지, 세로인지, 아니면 알 수 없는지(모호한지) 나타내요.
aria-owns string - DOM 계층 구조로 표현할 수 없는 관계에서 DOM 엘리먼트 사이의 시각적·기능적·맥락적 부모/자식 관계를 정의하려고 엘리먼트(들)를 식별해요.
aria-placeholder string - 컨트롤에 값이 없을 때 데이터 입력을 돕기 위한 짧은 힌트(단어나 짧은 문구)를 정의해요. 힌트는 예시 값이거나 기대 형식에 대한 간단한 설명일 수 있어요.
aria-posinset Numberish - 현재 listitem이나 treeitem 집합에서 엘리먼트의 순번이나 위치를 정의해요. 집합의 모든 엘리먼트가 DOM에 있으면 필요하지 않아요.
aria-pressed Booleanish | "mixed" - 토글 버튼의 현재 "pressed" 상태를 나타내요.
aria-readonly Booleanish - 엘리먼트가 편집은 불가능하지만 그 외에는 조작할 수 있음을 나타내요.
aria-relevant "text" | "additions" | "additions removals" | "additions text" | "all" | "removals" | "removals additions" | "removals text" | "text additions" | "text removals" - 라이브 영역 안의 접근성 트리가 변경될 때 사용자 에이전트가 어떤 알림을 발생시킬지 나타내요.
aria-required Booleanish - 폼을 제출하기 전에 해당 엘리먼트에 사용자 입력이 필요함을 나타내요.
aria-roledescription string - 엘리먼트 역할에 대해 사람이 읽을 수 있도록 작성자가 현지화한 설명을 정의해요.
aria-rowcount Numberish - 테이블, 그리드, 트리그리드의 전체 행 수를 정의해요.
aria-rowindex Numberish - 테이블, 그리드, 트리그리드의 전체 행 수를 기준으로 엘리먼트의 행 인덱스나 위치를 정의해요.
aria-rowspan Numberish - 테이블, 그리드, 트리그리드에서 셀이나 그리드셀이 차지하는 행 수를 정의해요.
aria-selected Booleanish - 여러 위젯의 현재 "selected" 상태를 나타내요.
aria-setsize Numberish - 현재 listitem이나 treeitem 집합의 항목 수를 정의해요. 집합의 모든 엘리먼트가 DOM에 있으면 필요하지 않아요.
aria-sort "none" | "ascending" | "descending" | "other" - 테이블이나 그리드의 항목이 오름차순인지 내림차순인지 나타내요.
aria-valuemax Numberish - 범위 위젯에 허용되는 최댓값을 정의해요.
aria-valuemin Numberish - 범위 위젯에 허용되는 최솟값을 정의해요.
aria-valuenow Numberish - 범위 위젯의 현재 값을 정의해요.
aria-valuetext string - 범위 위젯에서 aria-valuenow에 대한 사람이 읽을 수 있는 대체 텍스트를 정의해요.
innerHTML string -
class ClassValue -
style StyleValue -
accesskey string -
contenteditable Booleanish | "inherit" | "plaintext-only" -
contextmenu string -
dir string -
draggable Booleanish -
enterkeyhint "enter" | "done" | "go" | "next" | "previous" | "search" | "send" -
enterKeyHint "enter" | "done" | "go" | "next" | "previous" | "search" | "send" -
hidden "" | Booleanish | "hidden" | "until-found" -
id string -
inert Booleanish -
lang string -
spellcheck Booleanish -
tabindex Numberish -
title string -
translate "yes" | "no" -
radiogroup string -
role string -
about string -
datatype string -
inlist any -
prefix string -
property string -
resource string -
typeof string -
vocab string -
autocapitalize string -
autocorrect string -
autosave string -
color string -
itemprop string -
itemscope Booleanish -
itemtype string -
itemid string -
itemref string -
results Numberish -
security string -
unselectable "on" | "off" -
inputmode "text" | "search" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" - 엘리먼트나 그 내용을 편집하는 동안 사용자가 입력할 수 있는 데이터 유형을 알려 줘요.
is string - 표준 HTML 엘리먼트가 정의된 커스텀 빌트인 엘리먼트처럼 동작하도록 지정해요.
exportparts string -
part string -
autocomplete string -
autofocus Booleanish -
cols Numberish -
dirname string -
disabled Booleanish -
form string -
maxlength Numberish -
minlength Numberish -
placeholder string -
readonly Booleanish -
required Booleanish -
rows Numberish -
value null | string | number | readonly string[] -
wrap string -
onCopy Function -
onCut Function -
onPaste Function -
onCompositionend Function -
onCompositionstart Function -
onCompositionupdate Function -
onDrag Function -
onDragend Function -
onDragenter Function -
onDragexit Function -
onDragleave Function -
onDragover Function -
onDragstart Function -
onDrop Function -
onFocus Function -
onFocusin Function -
onFocusout Function -
onBlur Function -
onChange Function -
onBeforeinput Function -
onFormdata Function -
onInput Function -
onReset Function -
onSubmit Function -
onInvalid Function -
onFullscreenchange Function -
onFullscreenerror Function -
onLoad Function -
onError Function -
onKeydown Function -
onKeypress Function -
onKeyup Function -
onDblclick Function -
onMousedown Function -
onMouseenter Function -
onMouseleave Function -
onMousemove Function -
onMouseout Function -
onMouseover Function -
onMouseup Function -
onAbort Function -
onCanplay Function -
onCanplaythrough Function -
onDurationchange Function -
onEmptied Function -
onEncrypted Function -
onEnded Function -
onLoadeddata Function -
onLoadedmetadata Function -
onLoadstart Function -
onPause Function -
onPlay Function -
onPlaying Function -
onProgress Function -
onRatechange Function -
onSeeked Function -
onSeeking Function -
onStalled Function -
onSuspend Function -
onTimeupdate Function -
onVolumechange Function -
onWaiting Function -
onSelect Function -
onScroll Function -
onScrollend Function -
onTouchcancel Function -
onTouchend Function -
onTouchmove Function -
onTouchstart Function -
onAuxclick Function -
onClick Function -
onContextmenu Function -
onGotpointercapture Function -
onLostpointercapture Function -
onPointerdown Function -
onPointermove Function -
onPointerup Function -
onPointercancel Function -
onPointerenter Function -
onPointerleave Function -
onPointerover Function -
onPointerout Function -
onBeforetoggle Function -
onToggle Function -
onWheel Function -
onAnimationcancel Function -
onAnimationstart Function -
onAnimationend Function -
onAnimationiteration Function -
onSecuritypolicyviolation Function -
onTransitioncancel Function -
onTransitionend Function -
onTransitionrun Function -
onTransitionstart Function -
modelValue Nullable - 컴포넌트의 값이에요.
defaultValue Nullable - modelValue로 제어하지 않을 때 입력의 기본값이에요.
name string - 엘리먼트의 name 속성이에요. 주로 폼 제출에 써요.
autoResize boolean false 설정하면 입력하는 동안 textarea의 높이가 변해요.
size HintedString<"small" | "large"> - 컴포넌트의 크기를 정의해요.
invalid boolean false 설정하면 컴포넌트에 invalid 상태 스타일이 적용돼야 함을 지정해요.
variant null | HintedString<"outlined" | "filled"> null 컴포넌트의 입력 variant를 지정해요.
fluid boolean null 켜면 컨테이너 너비의 100%를 차지해요.
formControl Record<string, any> - 폼 컨트롤 객체예요. 주로 검증과 폼 상태를 다룰 때 써요.
dt any - 컴포넌트에 디자인 토큰으로 스코프된 CSS 변수를 만들어 줘요.
pt PassThrough - 컴포넌트 내부 DOM 엘리먼트에 속성을 전달할 때 써요.
ptOptions any - 컴포넌트의 passthrough(pt) 옵션을 설정할 때 써요.
unstyled boolean false 켜면 코어에서 컴포넌트 관련 스타일을 제거해요.

Emits

컴포넌트가 내보내는 이벤트예요.

이름 파라미터 설명
update:modelValue Function

패스 스루 옵션 (Pass Through Options)

패스 스루를 사용하면 컴포넌트 내부 DOM 엘리먼트에 직접 속성을 전달할 수 있어요.

이름 타입 설명
root TextareaPassThroughOptionType root의 DOM 엘리먼트에 속성을 전달할 때 써요.
hooks any 모든 라이프사이클 훅을 다룰 때 써요.

테미닝 (Theming)

CSS 클래스 (CSS Classes)

클래스 설명
p-textarea 루트 엘리먼트의 클래스 이름

디자인 토큰 (Design Tokens)

토큰 CSS 변수 설명
textarea.background --p-textarea-background 루트의 배경
textarea.disabled.background --p-textarea-disabled-background 루트의 비활성 배경
textarea.filled.background --p-textarea-filled-background 루트의 채우기 배경
textarea.filled.hover.background --p-textarea-filled-hover-background 루트의 채우기 호버 배경
textarea.filled.focus.background --p-textarea-filled-focus-background 루트의 채우기 포커스 배경
textarea.border.color --p-textarea-border-color 루트의 테두리 색
textarea.hover.border.color --p-textarea-hover-border-color 루트의 호버 테두리 색
textarea.focus.border.color --p-textarea-focus-border-color 루트의 포커스 테두리 색
textarea.invalid.border.color --p-textarea-invalid-border-color 루트의 invalid 테두리 색
textarea.color --p-textarea-color 루트의 글자색
textarea.disabled.color --p-textarea-disabled-color 루트의 비활성 글자색
textarea.placeholder.color --p-textarea-placeholder-color 루트의 플레이스홀더 색
textarea.invalid.placeholder.color --p-textarea-invalid-placeholder-color 루트의 invalid 플레이스홀더 색
textarea.shadow --p-textarea-shadow 루트의 그림자
textarea.padding.x --p-textarea-padding-x 루트의 가로 패딩
textarea.padding.y --p-textarea-padding-y 루트의 세로 패딩
textarea.border.radius --p-textarea-border-radius 루트의 테두리 반경
textarea.focus.ring.width --p-textarea-focus-ring-width 루트의 포커스 링 너비
textarea.focus.ring.style --p-textarea-focus-ring-style 루트의 포커스 링 스타일
textarea.focus.ring.color --p-textarea-focus-ring-color 루트의 포커스 링 색
textarea.focus.ring.offset --p-textarea-focus-ring-offset 루트의 포커스 링 오프셋
textarea.focus.ring.shadow --p-textarea-focus-ring-shadow 루트의 포커스 링 그림자
textarea.transition.duration --p-textarea-transition-duration 루트의 전환 지속 시간
textarea.sm.font.size --p-textarea-sm-font-size 루트의 small 글자 크기
textarea.sm.padding.x --p-textarea-sm-padding-x 루트의 small 가로 패딩
textarea.sm.padding.y --p-textarea-sm-padding-y 루트의 small 세로 패딩
textarea.lg.font.size --p-textarea-lg-font-size 루트의 large 글자 크기
textarea.lg.padding.x --p-textarea-lg-padding-x 루트의 large 가로 패딩
textarea.lg.padding.y --p-textarea-lg-padding-y 루트의 large 세로 패딩

더 알아보기 (Learn more)

표준 textarea에 스타일링과 자동 높이 조절을 얹는 PrimeVue의 Textarea 컴포넌트 문서예요. 기본 사용법부터 autoResize, 플로트 라벨, 폼 통합, 크기와 variant 제어까지 다루고, props·emits·패스 스루·디자인 토큰 목록도 함께 정리돼 있어요.