Vue IconField 컴포넌트
IconField는 입력 요소와 아이콘을 감싸는 컴포넌트예요. 검색창처럼 입력 필드 안이나 옆에 아이콘을 넣을 때 사용해요.
출처: 문서
본문
Vue IconField
IconField wraps an input and an icon.
Import
import IconField from 'primevue/iconfield';
import InputIcon from 'primevue/inputicon';
Accessibility
Screen Reader IconField와 InputIcon은 어떤 role이나 속성도 필요로 하지 않아요. Keyboard Support 이 컴포넌트에는 인터랙티브 요소가 없어요.
Basic
IconField는 InputIcon과 입력 필드 컴포넌트를 감싸요.
<IconField>
<InputIcon class="pi pi-search" />
<InputText v-model="value1" placeholder="Search" />
</IconField>
<IconField>
<InputText v-model="value2" variant="filled" />
<InputIcon class="pi pi-spin pi-spinner" />
</IconField>
Float Label
FloatLabel은 라벨을 폼 요소와 시각적으로 통합해요. 자세한 내용은 FloatLabel 문서를 참고하세요.
<FloatLabel>
<IconField>
<InputIcon class="pi pi-search" />
<InputText id="over_label" v-model="value1" autocomplete="off" />
</IconField>
<label for="over_label">Over Label</label>
</FloatLabel>
<FloatLabel variant="in">
<IconField>
<InputIcon class="pi pi-search" />
<InputText id="in_label" v-model="value2" autocomplete="off" variant="filled" />
</IconField>
<label for="in_label">In Label</label>
</FloatLabel>
<FloatLabel variant="on">
<IconField>
<InputIcon class="pi pi-search" />
<InputText id="on_label" v-model="value3" autocomplete="off" />
</IconField>
<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>
<IconField>
<InputIcon class="pi pi-search" />
<InputText id="over_label" v-model="value1" autocomplete="off" />
</IconField>
<label for="over_label">Over Label</label>
</FloatLabel>
<FloatLabel variant="in">
<IconField>
<InputIcon class="pi pi-search" />
<InputText id="in_label" v-model="value2" autocomplete="off" variant="filled" />
</IconField>
<label for="in_label">In Label</label>
</FloatLabel>
<FloatLabel variant="on">
<IconField>
<InputIcon class="pi pi-search" />
<InputText id="on_label" v-model="value3" autocomplete="off" />
</IconField>
<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>
Ifta Label
IftaLabel은 인필드(infield) 상단 정렬 라벨을 만들 때 사용해요. 자세한 내용은 IftaLabel 문서를 참고하세요.
<IftaLabel>
<IconField>
<InputIcon class="pi pi-user" />
<InputText id="username" v-model="value" variant="filled" />
</IconField>
<label for="username">Username</label>
</IftaLabel>
Composition API Example
<template>
<div class="card flex justify-center">
<IftaLabel>
<IconField>
<InputIcon class="pi pi-user" />
<InputText id="username" v-model="value" variant="filled" />
</IconField>
<label for="username">Username</label>
</IftaLabel>
</div>
</template>
<script setup>
import { ref } from 'vue';
const value = ref(null);
<\/script>
Sizes
IconField는 입력 필드의 size 설정과 호환돼요.
<IconField>
<InputIcon class="pi pi-search" />
<InputText v-model="value1" placeholder="Small" size="small" />
</IconField>
<IconField>
<InputIcon class="pi pi-search" />
<InputText v-model="value2" placeholder="Normal" />
</IconField>
<IconField>
<InputText v-model="value3" placeholder="Large" size="large" />
<InputIcon class="pi pi-spin pi-spinner" />
</IconField>
Composition API Example
<template>
<div class="card flex flex-col items-center gap-4">
<IconField>
<InputIcon class="pi pi-search" />
<InputText v-model="value1" placeholder="Small" size="small" />
</IconField>
<IconField>
<InputIcon class="pi pi-search" />
<InputText v-model="value2" placeholder="Normal" />
</IconField>
<IconField>
<InputText v-model="value3" placeholder="Large" size="large" />
<InputIcon class="pi pi-spin pi-spinner" />
</IconField>
</div>
</template>
<script setup>
import { ref } from 'vue';
const value1 = ref(null);
const value2 = ref(null);
const value3 = ref(null);
<\/script>
Template
InputIcon 안의 커스텀 콘텐츠는 자식으로 정의해요.
<IconField>
<InputIcon>
<svg width="35" height="40" viewBox="0 0 35 40" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="..." fill="var(--p-primary-color)" />
<path d="..." fill="var(--p-text-color)" />
</svg>
</InputIcon>
<InputText v-model="value" placeholder="Search" />
</IconField>
Composition API Example
<template>
<div class="card flex justify-center">
<IconField>
<InputIcon>
<svg width="35" height="40" viewBox="0 0 35 40" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="..." fill="var(--p-primary-color)" />
<path d="..." fill="var(--p-text-color)" />
</svg>
</InputIcon>
<InputText v-model="value" placeholder="Search" />
</IconField>
</div>
</template>
<script setup>
import { ref } from 'vue';
const value = ref(null);
<\/script>
Icon Field
Props
| Name | Type | Default | Description |
|---|---|---|---|
| dt | any | - | It generates scoped CSS variables using design tokens for the component. |
| pt | PassThrough<IconFieldPassThroughOptions> | - | 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. |
Pass Through Options
| Name | Type | Description |
|---|---|---|
| root | IconFieldPassThroughOptionType | Used to pass attributes to the root's DOM element. |
| hooks | any | Used to manage all lifecycle hooks. |
Theming
CSS Classes
| Class | Description |
|---|---|
| p-iconfield | Class name of the root element |
Design Tokens
| Token | CSS Variable | Description |
|---|---|---|
| iconfield.icon.color | --p-iconfield-icon-color | Color of icon |