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

Vue FloatLabel 컴포넌트

원문 보기 위키 갱신

FloatLabel은 라벨을 폼 요소와 시각적으로 통합하는 컴포넌트예요. 입력 전에는 라벨이 기본 위치에 있다가 포커스나 값 입력 시 떠 오르는(floating) 형태로 바뀌어요.

출처: 문서

본문

Vue Float Label

FloatLabel visually integrates a label with its form element.

Import

import FloatLabel from 'primevue/floatlabel';

Accessibility

Screen Reader FloatLabel은 어떤 role이나 속성도 필요로 하지 않아요. Keyboard Support 이 컴포넌트에는 인터랙티브 요소가 없어요.

Basic

FloatLabel은 입력 요소와 그 라벨을 감싸서 사용해요.

<FloatLabel>
    <InputText id="username" v-model="value" />
    <label for="username">Username</label>
</FloatLabel>

Invalid

폼 요소가 유효하지 않을 때는 라벨도 함께 강조돼요.

<FloatLabel>
    <InputText id="value1" v-model="value1" :invalid="!value1" />
    <label for="value1">Username</label>
</FloatLabel>

<FloatLabel variant="in">
    <InputText id="value2" v-model="value2" :invalid="!value2" />
    <label for="value2">Username</label>
</FloatLabel>

<FloatLabel variant="on">
    <InputText id="value3" v-model="value3" :invalid="!value3" />
    <label for="value3">Username</label>
</FloatLabel>
Composition API Example
<template>
    <div class="card flex flex-wrap justify-center items-end gap-4">
        <FloatLabel>
            <InputText id="value1" v-model="value1" :invalid="!value1" />
            <label for="value1">Username</label>
        </FloatLabel>

        <FloatLabel variant="in">
            <InputText id="value2" v-model="value2" :invalid="!value2" />
            <label for="value2">Username</label>
        </FloatLabel>

        <FloatLabel variant="on">
            <InputText id="value3" v-model="value3" :invalid="!value3" />
            <label for="value3">Username</label>
        </FloatLabel>
    </div>
</template>

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

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

Variants

variant 프로퍼티는 라벨의 위치를 정의해요. 기본값은 over이고, in과 on이 대안이에요.

<FloatLabel variant="in">
    <InputText id="in_label" v-model="value1" autocomplete="off" />
    <label for="in_label">In Label</label>
</FloatLabel>

<FloatLabel variant="on">
    <InputText id="on_label" v-model="value2" autocomplete="off" />
    <label for="on_label">On Label</label>
</FloatLabel>
Composition API Example
<div class="card flex flex-wrap justify-center items-end gap-4">
    <div class="card flex flex-wrap justify-center gap-4">
        <FloatLabel variant="in">
            <InputText id="in_label" v-model="value1" autocomplete="off" />
            <label for="in_label">In Label</label>
        </FloatLabel>

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

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

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

Float Label

Props

Name Type Default Description
dt any - It generates scoped CSS variables using design tokens for the component.
pt PassThrough - Used to pass attributes to DOM elements inside the component.
ptOptions any - Used to configure passthrough(pt) options of the component.
unstyled boolean false When enabled, it removes component related styles in the core.
variant HintedString<"on" | "in" | "over"> over Defines the positioning of the label relative to the input.

Slots

Name Parameters Description
default Function

Pass Through Options

Name Type Description
root FloatLabelPassThroughOptionType Used to pass attributes to the root's DOM element.
hooks any Used to manage all lifecycle hooks.

Theming

CSS Classes

Class Description
p-floatlabel Class name of the root element

Design Tokens

Token CSS Variable Description
floatlabel.color --p-floatlabel-color Color of root
floatlabel.focus.color --p-floatlabel-focus-color Focus color of root
floatlabel.active.color --p-floatlabel-active-color Active color of root
floatlabel.invalid.color --p-floatlabel-invalid-color Invalid color of root
floatlabel.transition.duration --p-floatlabel-transition-duration Transition duration of root
floatlabel.position.x --p-floatlabel-position-x Position x of root
floatlabel.position.y --p-floatlabel-position-y Position y of root
floatlabel.font.weight --p-floatlabel-font-weight Font weight of root
floatlabel.active.font.size --p-floatlabel-active-font-size Active font size of root
floatlabel.active.font.weight --p-floatlabel-active-font-weight Active font weight of root
floatlabel.over.active.top --p-floatlabel-over-active-top Active top of over
floatlabel.in.input.padding.top --p-floatlabel-in-input-padding-top Input padding top of in
floatlabel.in.input.padding.bottom --p-floatlabel-in-input-padding-bottom Input padding bottom of in
floatlabel.in.active.top --p-floatlabel-in-active-top Active top of in
floatlabel.on.border.radius --p-floatlabel-on-border-radius Border radius of on
floatlabel.on.active.background --p-floatlabel-on-active-background Active background of on
floatlabel.on.active.padding --p-floatlabel-on-active-padding Active padding of on

더 알아보기 (Learn more)