Vue Tooltip - Getting Started
Tooltip is a UI component that allows you to display information over a specific element in your application.
This tutorial guides you through the following steps:
- Add a Tooltip to a page and configure core component settings.
- Customize Tooltip appearance.
The following live example demonstrates the result:
Each section in this tutorial describes a single configuration step. You can find the complete source code in the following GitHub repository:
Create and Configure Tooltip
Add DevExtreme to your Vue application and use the code below to create a Tooltip. To display the component, specify a target and define the showEvent or visible property.
- <script setup lang="ts">
- import { DxTooltip } from 'devextreme-vue/tooltip';
- import 'devextreme/dist/css/dx.fluent.blue.light.css';
- </script>
- <template>
- <DxTooltip
- target="#target"
- show-event="mouseenter"
- />
- </template>
This example creates three Button components and assigns Tooltips to them. Button ID attributes are specified as Tooltip targets. Additionally, this example configures the hideEvent property for all Tooltips:
- <script setup lang="ts">
- import 'devextreme/dist/css/dx.fluent.blue.light.css';
- import { DxButton } from 'devextreme-vue/button';
- import { DxTooltip } from 'devextreme-vue/tooltip';
- </script>
- <template>
- <div class="dx-viewport">
- <div class="buttons">
- <DxButton
- id="like"
- icon="like"
- />
- <DxButton
- id="trash"
- icon="trash"
- />
- <DxButton
- id="info"
- icon="info"
- />
- </div>
- <div class="tooltips">
- <DxTooltip
- target="#like"
- show-event="mouseenter"
- hide-event="mouseleave"
- />
- <DxTooltip
- target="#trash"
- show-event="mouseenter"
- hide-event="mouseleave"
- />
- <DxTooltip
- target="#info"
- show-event="mouseenter"
- hide-event="mouseleave"
- />
- </div>
- </div>
- </template>
Customize Tooltip
To customize Tooltip content, specify contentTemplate. If you assign a string to this property, Tooltip displays plain text in its container:
- <template>
- <div class="tooltips">
- <DxTooltip
- content-template="Like"
- />
- <DxTooltip
- content-template="trashTooltip"
- >
- <template #trashTooltip>
- <div class="red-tooltip">Delete</div>
- </template>
- </DxTooltip>
- <DxTooltip
- content-template="infoTooltip"
- >
- <template #infoTooltip>
- <div class="blue-tooltip">Info</div>
- </template>
- </DxTooltip>
- </div>
- </template>
You can use CSS to customize the Tooltip's appearance. The code snippets above assigned CSS classes to all tooltips. This example defines those styles (.red-tooltip and .blue-tooltip):
- .dx-overlay-content:has(.blue-tooltip),
- .dx-overlay-content:has(.blue-tooltip) .dx-popover-arrow::after {
- background-color: #0f6cbd;
- color: white;
- }
- .dx-overlay-content:has(.red-tooltip),
- .dx-overlay-content:has(.red-tooltip) .dx-popover-arrow::after {
- background-color: #d13438;
- color: white;
- }