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

InputText — Vue 입력 컴포넌트

원문 보기 위키 갱신

InputText는 표준 input 요소에 테마를 덧붙인 Vue 입력 컴포넌트예요. 기본 텍스트 입력에 크기, variant, invalid 상태 같은 PrimeVue 스타일 기능을 그대로 쓸 수 있게 해줘요.

출처: 문서

본문

가져오기 (Import)

컴포넌트를 쓰려면 먼저 primevue/inputtext에서 가져와요.

import InputText from 'primevue/inputtext';

접근성 (Accessibility)

InputText는 네이티브 input 요소를 렌더링해요. 그래서 전달한 prop이 암묵적으로 그대로 포함되죠. 스크린 리더를 위한 컴포넌트 설명은 두 가지 방식으로 제공할 수 있어요. id prop과 짝지은 label 태그를 쓰거나, aria-labelledby, aria-label prop을 쓰면 돼요. 키보드 지원으로는 Tab 키가 입력 요소로 포커스를 옮겨요.

<label for="firstname">Firstname</label>
<InputText id="firstname" />

<span id="lastname">Lastname</span>
<InputText aria-labelledby="lastname" />

<InputText aria-label="Age" />

예시 코드에는 label 방식과 ARIA 속성 방식이 나란히 담겨 있어요. 가능하면 id와 연결한 label 태그 방식을 기본으로 삼는 게 좋아요.

기본 (Basic)

InputText는 v-model 속성으로 값과 양방향 바인딩을 해요.

<InputText type="text" v-model="value" />

비활성화 (Disabled)

disabled가 있으면 요소를 편집하거나 포커스를 줄 수 없어요.

<InputText v-model="value" disabled placeholder="Disabled" />
Composition API 예제
<template>
    <div class="card flex justify-center">
        <InputText v-model="value" disabled placeholder="Disabled" />
    </div>
</template>

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

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

채움 스타일 (Filled)

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

<InputText type="text" v-model="value" variant="filled" />
Composition API 예제
<template>
    <div class="card flex justify-center">
        <InputText v-model="value" type="text" variant="filled" />
    </div>
</template>

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

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

플로트 라벨 (Float Label)

FloatLabel은 라벨을 폼 요소와 시각적으로 통합해줘요. 자세한 내용은 FloatLabel 문서를 참고하세요.

<FloatLabel>
    <InputText id="over_label" v-model="value1" />
    <label for="over_label">Over Label</label>
</FloatLabel>

<FloatLabel variant="in">
    <InputText id="in_label" v-model="value2" variant="filled" />
    <label for="in_label">In Label</label>
</FloatLabel>

<FloatLabel variant="on">
    <InputText id="on_label" v-model="value3" />
    <label for="on_label">On Label</label>
</FloatLabel>

over(기본), in, on 세 가지 variant로 라벨이 입력 요소와 겹쳐 보이는 방식을 고를 수 있어요.

Composition API 예제
<template>
    <div class="card flex flex-wrap justify-center items-end gap-4">
        <FloatLabel>
            <InputText id="over_label" v-model="value1" />
            <label for="over_label">Over Label</label>
        </FloatLabel>

        <FloatLabel variant="in">
            <InputText id="in_label" v-model="value2" variant="filled" />
            <label for="in_label">In Label</label>
        </FloatLabel>

        <FloatLabel variant="on">
            <InputText id="on_label" v-model="value3" />
            <label for="on_label">On Label</label>
        </FloatLabel>
    </div>
</template>

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

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

전체 너비 (Fluid)

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

<InputText type="text" v-model="value" fluid />
Composition API 예제
<template>
    <div class="card">
        <InputText type="text" v-model="value" fluid />
    </div>
</template>

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

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

폼 (Forms)

InputText는 PrimeVue Forms 라이브러리와 매끄럽게 연동돼요.

<Form v-slot="$form" :resolver="resolver" :initialValues="initialValues" @submit="onFormSubmit" class="flex justify-center flex-col gap-4">
    <div class="flex flex-col gap-1">
        <InputText name="username" type="text" placeholder="Username" />
        <Message v-if="$form.username?.invalid" severity="error" size="small" variant="simple">{{ $form.username.error?.message }}</Message>
    </div>
    <div class="flex flex-col gap-1">
        <InputText name="email" type="text" placeholder="Email" />
        <Message v-if="$form.email?.invalid" severity="error" size="small" variant="simple">{{ $form.email.error?.message }}</Message>
    </div>
    <Button type="submit" severity="secondary" label="Submit" />
</Form>
Composition API 예제
<template>
    <div class="card flex justify-center">
        <Form v-slot="$form" :resolver="resolver" :initialValues="initialValues" @submit="onFormSubmit" class="flex flex-col gap-4 w-full sm:w-56">
            <div class="flex flex-col gap-1">
                <InputText name="username" type="text" placeholder="Username" fluid />
                <Message v-if="$form.username?.invalid" severity="error" size="small" variant="simple">{{ $form.username.error?.message }}</Message>
            </div>
            <div class="flex flex-col gap-1">
                <InputText name="email" type="text" placeholder="Email" fluid />
                <Message v-if="$form.email?.invalid" severity="error" size="small" variant="simple">{{ $form.email.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({
    username: '',
    email: ''
});

const resolver = ref(zodResolver(
    z.object({
        username: z.string().min(1, { message: 'Username is required.' }),
        email: z.string().min(1, { message: 'Email is required.' }).email({ message: 'Invalid email address.' })
    })
));

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

도움말 텍스트 (Help Text)

안내 문구는 Message 컴포넌트로 정의할 수 있어요.

<div class="flex flex-col gap-2">
    <label for="username">Username</label>
    <InputText id="username" v-model="value" aria-describedby="username-help" />
    <Message size="small" severity="secondary" variant="simple">Enter your username to reset your password.</Message>
</div>
Composition API 예제
<template>
    <div class="card flex justify-center">
        <div class="flex flex-col gap-2">
            <label for="username">Username</label>
            <InputText id="username" v-model="value" aria-describedby="username-help" />
            <Message size="small" severity="secondary" variant="simple">Enter your username to reset your password.</Message>
        </div>
    </div>
</template>

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

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

Ifta 라벨 (Ifta Label)

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

<IftaLabel>
    <InputText id="username" v-model="value" variant="filled" />
    <label for="username">Username</label>
</IftaLabel>
Composition API 예제
<template>
    <div class="card flex justify-center">
        <IftaLabel>
            <InputText id="username" v-model="value" variant="filled" />
            <label for="username">Username</label>
        </IftaLabel>
    </div>
</template>

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

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

유효성 오류 (Invalid)

invalid prop으로 검증 실패를 나타내는 invalid 상태를 표시해요. 폼 검증 라이브러리와 연동할 때 이 스타일을 활용할 수 있어요.

<InputText v-model="value1" :invalid="!value1" placeholder="Name" />
<InputText v-model="value2" :invalid="!value2" variant="filled" placeholder="Name" />
Composition API 예제
<template>
    <div class="card flex flex-wrap justify-center gap-4">
        <InputText v-model="value1" :invalid="!value1" placeholder="Name" />
        <InputText v-model="value2" :invalid="!value2" variant="filled" placeholder="Name" />
    </div>
</template>

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

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

크기 (Sizes)

InputText는 기본 크기 외에 small, large 크기를 제공해요.

<InputText v-model="value1" type="text" size="small" placeholder="Small" />
<InputText v-model="value2" type="text" placeholder="Normal" />
<InputText v-model="value3" type="text" size="large" placeholder="Large" />
Composition API 예제
<template>
    <div class="card flex flex-col items-center gap-4">
        <InputText v-model="value1" type="text" size="small" placeholder="Small" />
        <InputText v-model="value2" type="text" placeholder="Normal" />
        <InputText v-model="value3" type="text" size="large" placeholder="Large" />
    </div>
</template>

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

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

Input Text (컴포넌트 API)

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 계층만으로 표현할 수 없는 부모/자식 관계를 정의하려고 요소 식별
aria-placeholder string - 컨트롤에 값이 없을 때 입력을 돕는 짧은 힌트(예시 값 또는 기대 형식 설명) 정의
aria-posinset Numberish - 현재 리스트 항목이나 트리 항목 집합에서 요소의 번호·위치 정의. 집합 전체가 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 - 요소의 role에 대해 사람이 읽을 수 있는, 작성자가 현지화한 설명 정의
aria-rowcount Numberish - 테이블, 그리드, 트리그리드의 전체 행 수 정의
aria-rowindex Numberish - 테이블, 그리드, 트리그리드에서 요소의 행 인덱스(위치) 정의
aria-rowspan Numberish - 테이블, 그리드, 트리그리드에서 셀이 차지하는 행 수 정의
aria-selected Booleanish - 여러 위젯의 현재 "selected" 상태
aria-setsize Numberish - 현재 리스트 항목이나 트리 항목 집합의 항목 수 정의. 집합 전체가 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 -
accept string -
alt string -
autocomplete InputAutoCompleteAttribute -
autofocus Booleanish -
capture boolean | "user" | "environment" -
checked any[] | Set | Booleanish -
crossorigin string -
disabled Booleanish -
form string -
formaction string -
formenctype string -
formmethod string -
formnovalidate Booleanish -
formtarget string -
height Numberish -
indeterminate boolean -
list string -
max Numberish -
maxlength Numberish -
min Numberish -
minlength Numberish -
multiple Booleanish -
pattern string -
placeholder string -
readonly Booleanish -
required Booleanish -
src string -
step Numberish -
type InputTypeHTMLAttribute -
value any -
width Numberish -
onCancel Function -
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 속성, 주로 폼 제출에 사용
size null | HintedString<"small" | "large"> - 컴포넌트의 크기 정의
invalid null | boolean false 지정하면 컴포넌트에 invalid 상태 스타일이 적용됨
variant null | HintedString<"outlined" | "filled"> null 컴포넌트의 입력 variant 지정
fluid null | boolean null 활성화하면 컨테이너 너비의 100%를 차지
formControl Record<string, any> - 폼 컨트롤 객체, 주로 검증과 폼 상태 처리에 사용
dt any - 디자인 토큰으로 컴포넌트 범위의 CSS 변수 생성
pt PassThrough<InputTextPassThroughOptions> - 컴포넌트 내부 DOM 요소에 속성을 전달할 때 사용
ptOptions any - 컴포넌트의 passthrough(pt) 옵션 설정에 사용
unstyled boolean false 활성화하면 코어에서 컴포넌트 관련 스타일 제거

Pass Through Options (패스스루 옵션)

이름 타입 설명
root InputTextPassThroughOptionType 루트 DOM 요소에 속성을 전달할 때 사용
hooks any 모든 라이프사이클 훅을 관리할 때 사용

테마 (Theming)

CSS 클래스 (CSS Classes)

클래스 설명
p-inputtext 루트 요소의 클래스

디자인 토큰 (Design Tokens)

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

더 알아보기 (Learn more)

InputText는 PrimeVue 폼 컴포넌트의 기본이 되는 입력 요소예요. 라벨 배치가 고민되면 FloatLabel과 IftaLabel 문서를, 폼 검증 흐름은 Forms 문서를 함께 살펴보면 좋아요.