Vue Tooltip - Show and Hide the Tooltip

User Interaction

To specify when the Tooltip should be shown and hidden, set the showEvent and hideEvent properties. These properties can accept several events at once as well as an object.

  • <template>
  • <div>
  • <img id="image" src="https://url/to/an/image" />
  • <DxTooltip
  • target="#image"
  • show-event="dxhoverstart"
  • hide-event="dxhoverend">
  • <template>
  • <p>Tooltip content</p>
  • </template>
  • </DxTooltip>
  • </div>
  • </template>
  •  
  • <script>
  • import 'devextreme/dist/css/dx.light.css';
  •  
  • import { DxTooltip } from 'devextreme-vue/tooltip';
  •  
  • export default {
  • components: {
  • DxTooltip
  • }
  • }
  • </script>

The Tooltip can also be hidden when a user clicks outside it. To control this behavior of the Tooltip, use the hideOnOutsideClick property.

  • <template>
  • <div>
  • <img id="image" src="https://url/to/an/image" />
  • <DxTooltip
  • target="#image"
  • show-event="dxhoverstart"
  • hide-event="dxhoverend"
  • :hide-on-outside-click="false">
  • <template>
  • <p>Tooltip content</p>
  • </template>
  • </DxTooltip>
  • </div>
  • </template>
  •  
  • <script>
  • import 'devextreme/dist/css/dx.light.css';
  •  
  • import { DxTooltip } from 'devextreme-vue/tooltip';
  •  
  • export default {
  • components: {
  • DxTooltip
  • }
  • }
  • </script>

API

NOTE
In this article, the Button UI component is used to demonstrate how to show and hide the Tooltip. This choice is made for purely demonstrational purposes, and you can do the same operations using another UI component following the same guidelines.

To show or hide the Tooltip programmatically, bind the visible property of the Tooltip to a component property. After that, change this component property, and the Tooltip will appear or disappear.

  • <template>
  • <div>
  • <img id="image" src="https://url/to/an/image" />
  • <DxTooltip
  • target="#image"
  • v-model:visible="isTooltipVisible">
  • <template>
  • <p>Tooltip content</p>
  • </template>
  • </DxTooltip>
  • <DxButton
  • text="Show the Tooltip"
  • @click="showTooltip"
  • />
  • <DxButton
  • text="Hide the Tooltip"
  • @click="hideTooltip"
  • />
  • </div>
  • </template>
  •  
  • <script>
  • import 'devextreme/dist/css/dx.light.css';
  •  
  • import { DxTooltip } from 'devextreme-vue/tooltip';
  • import { DxButton } from 'devextreme-vue/button';
  •  
  • export default {
  • components: {
  • DxTooltip,
  • DxButton
  • },
  • data() {
  • return {
  • isTooltipVisible: false
  • }
  • },
  • methods: {
  • showTooltip() {
  • this.isTooltipVisible = true;
  • },
  • hideTooltip() {
  • this.isTooltipVisible = false;
  • }
  • }
  • }
  • </script>

Events

To execute certain commands before or after the Tooltip was shown/hidden, handle the showing, shown, hiding or hidden event. If the event handling function is not going to be changed during the lifetime of the UI component, assign it to the corresponding onEventName property when you configure the UI component.

  • <template>
  • <DxTooltip ...
  • @showing="onShowing"
  • @shown="onShown"
  • @hiding="onHiding"
  • @hidden="onHidden"
  • />
  • </template>
  •  
  • <script>
  • import 'devextreme/dist/css/dx.light.css';
  •  
  • import { DxTooltip } from 'devextreme-vue/tooltip';
  •  
  • export default {
  • components: {
  • DxTooltip
  • },
  • methods: {
  • onShowing(e) {
  • // Handler of the 'showing' event
  • },
  • onShown(e) {
  • // Handler of the 'shown' event
  • },
  • onHiding(e) {
  • // Handler of the 'hiding' event
  • },
  • onHidden(e) {
  • // Handler of the 'hidden' event
  • }
  • }
  • }
  • </script>
See Also