vTooltip
vTooltip is a Vue directive to display a text when the user hovers an element
Basic usage
Hover the buttons
Colors
Hover the buttons
Position
You can change the position of the tooltip by passing a position option or using the directive modifier (e.g. v-tooltip.top).
HTML content
You can also use HTML content in the tooltip by passing a string to the html option.
Customization
You can customize the tooltip by passing a panelClass or panelStyle option.
Trigger
You can change the trigger mode of the tooltip by passing a trigger option.
The default trigger is hover.
The adaptive trigger will use the click trigger on touch devices (mobile and tablet) and the hover trigger on non-touch devices (desktop).
Offset
The offset (in px) option allows you to adjust the position of the tooltip relative to the original element.
Open programmatically
Conditionally disable
Pass false, null or undefined as the binding value to silently disable the tooltip — no popover instance is created, no listeners are attached, and no warning is logged. This is the recommended way to skip the tooltip on the fly without conditionally rendering two different elements:
<script lang="ts" setup>
import { vTooltip } from 'maz-ui/directives'
import { computed, ref } from 'vue'
const label = ref<string>('')
const tooltipBinding = computed(() => label.value ? { text: label.value } : false)
</script>
<template>
<!-- When label is empty the directive becomes a no-op -->
<MazBtn v-tooltip="tooltipBinding">
Hover me
</MazBtn>
</template>If the binding switches back to a valid value later, the tooltip mounts as expected. Toggling the value off again destroys the existing popover instance.
Global install
Vue
import { vTooltipInstall } from 'maz-ui/directives'
import { createApp } from 'vue'
const app = createApp(App)
// Options are optional
app.use(vTooltipInstall, {
position: 'top',
color: 'primary',
})
app.mount('#app')Nuxt
Please refer to the Nuxt module documentation for more information.
Types
interface VTooltipOptions extends Partial<Omit<MazPopoverProps, 'modelValue'>> {
/**
* Text to display in the tooltip
*/
text?: string
/**
* HTML content (alternative to text)
*/
html?: string
/**
* Color variant of the tooltip
* @default default
*/
color?: MazPopoverProps['color']
/**
* Position of the tooltip
* @default top
*/
position?: PopoverPosition
/**
* Trigger of the tooltip
* @default hover
*/
trigger?: MazPopoverTrigger
/**
* Close on click outside
* @default false
*/
closeOnClickOutside?: boolean
/**
* Close on escape
* @default false
*/
closeOnEscape?: boolean
/**
* Open the tooltip
* @default false
*/
open?: boolean
}
type VTooltipBindingValue
= | string
| VTooltipOptions