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

Vue Tooltip 디렉티브

원문 보기 위키 갱신

Tooltip 디렉티브는 컴포넌트에 참고 정보(advisory information)를 보여 줘요. 마우스를 올리거나 포커스했을 때 작은 풍선 도움말이 나타나는 방식이에요.

출처: 문서

본문

Vue Tooltip Directive

Tooltip directive provides advisory information for a component.

Import

import Tooltip from 'primevue/tooltip';

app.directive('tooltip', Tooltip);

Accessibility

Screen Reader Tooltip 컴포넌트는 tooltip role을 사용하고, 표시될 때 생성된 tooltip의 id가 대상의 aria-describedby로 지정돼요. Keyboard Support Key Function escape 대상에 포커스가 있을 때 tooltip을 닫아요.

Auto Hide

기본적으로 마우스가 대상 요소를 벗어나면 tooltip이 숨겨져요. autoHide를 false로 설정하면 이 동작을 바꿔서 커서가 tooltip 위에 있는 동안 tooltip이 열려 있게 할 수 있어요.

<InputText v-tooltip.bottom="{ value: 'Enter your username', autoHide: false }" type="text" placeholder="autoHide: false" />
<InputText v-tooltip.bottom="'Enter your username'" type="text" placeholder="autoHide: true" />
Composition API Example
<template>
    <div class="card flex flex-wrap justify-center gap-2">
        <InputText v-tooltip.bottom="{ value: 'Enter your username', autoHide: false }" type="text" placeholder="autoHide: false" />
        <InputText v-tooltip.bottom="'Enter your username'" type="text" placeholder="autoHide: true" />
    </div>
</template>

Custom

커스텀 스타일과 콘텐츠를 담은 tooltip 샘플이에요.

<Button
    v-tooltip.bottom="{
        value: 'PrimeVue Rocks',
        pt: {
            arrow: {
                style: {
                    borderBottomColor: 'var(--p-primary-color)'
                }
            },
            text: '!bg-primary !text-primary-contrast !font-medium'
        }
    }"
    label="Button"
/>
Composition API Example
<template>
    <div class="card flex flex-wrap justify-center">
        <Button
            v-tooltip.bottom="{
                value: 'PrimeVue Rocks',
                pt: {
                    arrow: {
                        style: {
                            borderBottomColor: 'var(--p-primary-color)'
                        }
                    },
                    text: '!bg-primary !text-primary-contrast !font-medium'
                }
            }"
            severity="secondary"
            label="Button"
        />
    </div>
</template>

Delay

enter와 leave 이벤트의 지연은 각각 showDelay와 hideDelay 옵션으로 정의해요.

<Button v-tooltip="{ value: 'Confirm to proceed', showDelay: 1000, hideDelay: 300 }" label="Save" />
Composition API Example
<template>
    <div class="card flex flex-wrap justify-center">
        <Button v-tooltip="{ value: 'Confirm to proceed', showDelay: 1000, hideDelay: 300 }" label="Save" />
    </div>
</template>

Event

tooltip을 표시할 이벤트는 수정자(modifier)로 정의하고, 기본 이벤트는 hover예요.

<InputText v-tooltip.focus.top="'Enter your username'" type="text" placeholder="Focus" />
Composition API Example
<template>
    <div class="card flex flex-wrap justify-center">
        <InputText v-tooltip.focus.top="'Enter your username'" type="text" placeholder="Focus" />
    </div>
</template>

Position

tooltip 위치에는 네 가지 선택지가 있어요. 기본값은 right이고 대안은 top, bottom, left예요.

<InputText v-tooltip="'Enter your username'" type="text" placeholder="Right" />
<InputText v-tooltip.top="'Enter your username'" type="text" placeholder="Top" />
<InputText v-tooltip.bottom="'Enter your username'" type="text" placeholder="Bottom" />
<InputText v-tooltip.left="'Enter your username'" type="text" placeholder="Left" />
Composition API Example
<template>
    <div class="card flex flex-wrap justify-center gap-2">
        <InputText v-tooltip="'Enter your username'" type="text" placeholder="Right" />
        <InputText v-tooltip.top="'Enter your username'" type="text" placeholder="Top" />
        <InputText v-tooltip.bottom="'Enter your username'" type="text" placeholder="Bottom" />
        <InputText v-tooltip.left="'Enter your username'" type="text" placeholder="Left" />
    </div>
</template>

Tooltip

Pass Through Options

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

Theming

CSS Classes

Class Description
p-tooltip Class name of the root element
p-tooltip-arrow Class name of the arrow element
p-tooltip-text Class name of the text element

Design Tokens

Token CSS Variable Description
tooltip.max.width --p-tooltip-max-width Max width of root
tooltip.gutter --p-tooltip-gutter Gutter of root
tooltip.shadow --p-tooltip-shadow Shadow of root
tooltip.padding --p-tooltip-padding Padding of root
tooltip.border.radius --p-tooltip-border-radius Border radius of root
tooltip.background --p-tooltip-background Background of root
tooltip.color --p-tooltip-color Color of root

더 알아보기 (Learn more)