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

Vue Tag 컴포넌트

원문 보기 위키 갱신

Tag 컴포넌트는 콘텐츠를 분류(categorize)할 때 사용해요. 상태 배지나 라벨처럼 짧은 텍스트와 아이콘으로 항목의 속성을 표시하죠.

출처: 문서

본문

Vue Tag Component

Tag component is used to categorize content.

Import

import Tag from 'primevue/tag';

Accessibility

Screen Reader Tag는 기본적으로 어떤 role이나 속성도 포함하지 않지만, 모든 속성이 루트 요소로 전달되기 때문에 필요하다면 aria role과 속성을 추가할 수 있어요. 태그가 동적이라면 aria-live도 활용할 수 있어요. 배지를 탭 이동 가능하게 하려면 tabindex를 추가해 커스텀 키 핸들러를 구현하면 돼요. Keyboard Support 이 컴포넌트에는 인터랙티브 요소가 없어요.

Basic

태그의 라벨은 value 프로퍼티로 정의해요.

<Tag value="New"></Tag>

IconDoc

icon 프로퍼티로 값 옆에 폰트 아이콘을 표시할 수 있어요.

<Tag icon="pi pi-user" value="Primary"></Tag>
<Tag icon="pi pi-search" severity="secondary" value="Secondary"></Tag>
<Tag icon="pi pi-check" severity="success" value="Success"></Tag>
<Tag icon="pi pi-info-circle" severity="info" value="Info"></Tag>
<Tag icon="pi pi-exclamation-triangle" severity="warn" value="Warn"></Tag>
<Tag icon="pi pi-times" severity="danger" value="Danger"></Tag>
<Tag icon="pi pi-cog" severity="contrast" value="Contrast"></Tag>
Composition API Example
<template>
    <div class="card flex flex-wrap justify-center gap-2">
        <Tag icon="pi pi-user" value="Primary"></Tag>
        <Tag icon="pi pi-check" severity="success" value="Success"></Tag>
        <Tag icon="pi pi-search" severity="secondary" value="Secondary"></Tag>
        <Tag icon="pi pi-info-circle" severity="info" value="Info"></Tag>
        <Tag icon="pi pi-exclamation-triangle" severity="warn" value="Warn"></Tag>
        <Tag icon="pi pi-times" severity="danger" value="Danger"></Tag>
        <Tag icon="pi pi-cog" severity="contrast" value="Contrast"></Tag>
    </div>
</template>

<script setup>

<\/script>

Pill

rounded를 활성화하면 태그가 필(pill) 형태로 표시돼요.

<Tag value="Primary" rounded></Tag>
<Tag severity="secondary" value="Secondary" rounded></Tag>
<Tag severity="success" value="Success" rounded></Tag>
<Tag severity="info" value="Info" rounded></Tag>
<Tag severity="warn" value="Warn" rounded></Tag>
<Tag severity="danger" value="Danger" rounded></Tag>
<Tag severity="contrast" value="Contrast" rounded></Tag>
Composition API Example
<template>
    <div class="card flex flex-wrap justify-center gap-2">
        <Tag value="Primary" rounded></Tag>
        <Tag severity="success" value="Success" rounded></Tag>
        <Tag severity="secondary" value="Secondary" rounded></Tag>
        <Tag severity="info" value="Info" rounded></Tag>
        <Tag severity="warn" value="Warn" rounded></Tag>
        <Tag severity="danger" value="Danger" rounded></Tag>
        <Tag severity="contrast" value="Contrast" rounded></Tag>
    </div>
</template>

<script setup>

<\/script>

Severity

Severity는 태그의 변형(variant)을 정의해요.

<Tag value="Primary"></Tag>
<Tag severity="secondary" value="Secondary"></Tag>
<Tag severity="success" value="Success"></Tag>
<Tag severity="info" value="Info"></Tag>
<Tag severity="warn" value="Warn"></Tag>
<Tag severity="danger" value="Danger"></Tag>
<Tag severity="contrast" value="Contrast"></Tag>
Composition API Example
<template>
    <div class="flex flex-wrap justify-center gap-2">
        <Tag value="Primary"></Tag>
        <Tag severity="secondary" value="Secondary"></Tag>
        <Tag severity="success" value="Success"></Tag>
        <Tag severity="info" value="Info"></Tag>
        <Tag severity="warn" value="Warn"></Tag>
        <Tag severity="danger" value="Danger"></Tag>
        <Tag severity="contrast" value="Contrast"></Tag>
    </div>
</template>

<script setup>

<\/script>

Template

컴포넌트의 자식들이 템플릿용 콘텐츠로 전달돼요.

<Tag style="border: 2px solid var(--border-color); background: transparent; color: var(--text-color)">
    <div class="flex items-center gap-2 px-1">
        <img alt="Country" src="https://primefaces.org/cdn/primevue/images/flag/flag_placeholder.png" class="flag flag-it" style="width: 18px" />
        <span class="text-base">Italy</span>
    </div>
</Tag>
Composition API Example
<template>
    <div class="card flex justify-center">
        <Tag style="border: 2px solid var(--border-color); background: transparent; color: var(--text-color)">
            <div class="flex items-center gap-2 px-1">
                <img alt="Country" src="https://primefaces.org/cdn/primevue/images/flag/flag_placeholder.png" class="flag flag-it" style="width: 18px" />
                <span class="text-base">Italy</span>
            </div>
        </Tag>
    </div>
</template>

<script setup>
<\/script>

Tag

Props

Name Type Default Description
value any - Value to display inside the tag.
severity HintedString<"secondary" | "info" | "success" | "warn" | "danger" | "contrast"> - Severity type of the tag.
rounded boolean false Whether the corners of the tag are rounded.
icon string - Icon of the tag to display next to the value.
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.

Pass Through Options

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

Theming

CSS Classes

Class Description
p-tag Class name of the root element
p-tag-icon Class name of the icon element
p-tag-label Class name of the label element

Design Tokens

Token CSS Variable Description
tag.font.size --p-tag-font-size Font size of root
tag.font.weight --p-tag-font-weight Font weight of root
tag.padding --p-tag-padding Padding of root
tag.gap --p-tag-gap Gap of root
tag.border.radius --p-tag-border-radius Border radius of root
tag.rounded.border.radius --p-tag-rounded-border-radius Rounded border radius of root
tag.icon.size --p-tag-icon-size Size of icon
tag.primary.background --p-tag-primary-background Background of primary
tag.primary.color --p-tag-primary-color Color of primary
tag.secondary.background --p-tag-secondary-background Background of secondary
tag.secondary.color --p-tag-secondary-color Color of secondary
tag.success.background --p-tag-success-background Background of success
tag.success.color --p-tag-success-color Color of success
tag.info.background --p-tag-info-background Background of info
tag.info.color --p-tag-info-color Color of info
tag.warn.background --p-tag-warn-background Background of warn
tag.warn.color --p-tag-warn-color Color of warn
tag.danger.background --p-tag-danger-background Background of danger
tag.danger.color --p-tag-danger-color Color of danger
tag.contrast.background --p-tag-contrast-background Background of contrast
tag.contrast.color --p-tag-contrast-color Color of contrast

더 알아보기 (Learn more)