BaseTooltip · A simple tooltip component.
<template>
<BaseTooltip content="Tooltip content">
<BaseButton>
Button
</BaseButton>
</BaseTooltip>
</template>
This component has a slot that you can use to add your content. You can customize the tooltip's visual style by using the available props.
<template>
<BaseTooltip>
<!-- Your content here -->
</BaseTooltip>
</template>
This component has props that you can use to modify its visual style and behavior.
| Prop | Type |
|---|---|
variantdefault: "default" | "default" | "primary" | "dark" | "muted" | "none" |
roundeddefault: "md" | "none" | "sm" | "md" | "lg" | "full" |
contentdefault: - | string |
bindingsdefault: {} | { trigger?: TooltipTriggerProps; portal?: TooltipPortalProps; content?: TooltipContentProps; arrow?: TooltipArrowProps; } |
default-opendefault: - | booleanThe open state of the tooltip when it is initially rendered. Use when you do not need to control its open state. |
opendefault: - | booleanThe controlled open state of the tooltip. |
delay-durationdefault: - | numberOverride the duration given to the `Provider` to customise the open delay for a specific tooltip. |
disable-hoverable-contentdefault: - | booleanPrevents Tooltip.Content from remaining open when hovering. Disabling this has accessibility consequences. Inherits from Tooltip.Provider. |
disable-closing-triggerdefault: - | booleanWhen `true`, clicking on trigger will not close the content. |
disableddefault: - | booleanWhen `true`, disable tooltip |
ignore-non-keyboard-focusdefault: - | booleanPrevent the tooltip from opening if the focus did not come from the keyboard by matching against the `:focus-visible` selector. This is useful if you want to avoid opening it when switching browser tabs or closing a dialog. |
| Event | Emitted Value Type |
|---|---|
update:open | [value: boolean] |
| Slot | Type |
|---|---|
#default | { open: any; } |
#content | { open: any; } |
Your can override the component default CSS variables in your main.css file.
@theme {
/* Default popup variables */
--color-popup-default-bg: var(--color-portal-default-bg);
--color-popup-default-border: var(--color-portal-default-border);
--color-popup-default-text: var(--color-portal-default-item-text);
/* Muted popup variables */
--color-popup-muted-bg: var(--color-portal-muted-bg);
--color-popup-muted-border: var(--color-portal-muted-border);
--color-popup-muted-text: var(--color-portal-muted-item-text);
/* Dark popup variables */
--color-popup-dark-bg: var(--color-muted-950);
--color-popup-dark-border: var(--color-muted-950);
--color-popup-dark-text: var(--color-white);
}
Use the variant prop to change color of the tooltip.
<template>
<BaseTooltip content="Tooltip content">
<BaseButton>
Button
</BaseButton>
</BaseTooltip>
<BaseTooltip variant="muted">
<template #content>
Tooltip content muted
</template>
<BaseButton>
Button
</BaseButton>
</BaseTooltip>
<BaseTooltip variant="dark">
<template #content>
Tooltip content dark
</template>
<BaseButton>
Button
</BaseButton>
</BaseTooltip>
<BaseTooltip variant="primary">
<template #content>
Tooltip content primary
</template>
<BaseButton>
Button
</BaseButton>
</BaseTooltip>
</template>
Use the content slot to add custom content to the tooltip. add a tabindex to the trigger element to make it focusable.
<template>
<BaseTooltip>
<template #content>
<BaseTag class="flex items-center gap-1">
<Icon name="lucide:circle-help" />
<span>Tooltip link</span>
</BaseTag>
</template>
<span
tabindex="0"
class="inline-block outline-none focus-visible:text-primary-base hover:text-primary-base cursor-help underline underline-offset-4"
>
consectetur
</span>
</BaseTooltip>
</template>
Use the disable-closing-trigger prop to prevent the tooltip from closing when the trigger is activated. Use the bindings prop to customize the tooltip's position.
<template>
<BaseTooltip>
<template #content>
Quam quidem partem accusationis admiratus sum et moleste tuli potissimum esse Atratino datam. Neque enim decebat neque aetas illa postulabat neque, id quod animadvertere poteratis, pudor patiebatur optimi adulescentis in tali illum oratione versari. Vellem aliquis ex vobis robustioribus hunc male dicendi locum suscepisset; aliquanto liberius et fortius et magis more nostro refutaremus istam male dicendi licentiam. Tecum, Atratine, agam lenius, quod et pudor tuus moderatur orationi meae et meum erga te parentemque tuum beneficium tueri debeo.
</template>
<BaseButton>
Button
</BaseButton>
</BaseTooltip>
<div class="max-w-sm">
<BaseTooltip disable-closing-trigger :bindings="{ content: { align: 'start' } }">
<template #content>
Tooltip content
</template>
<BaseInput placeholder="I can help" />
</BaseTooltip>
</div>
<BaseTooltip disable-closing-trigger>
<template #content>
Tooltip content
</template>
<span tabindex="0" class="focus-visible:nui-focus rounded-md">
<BaseButton disabled>
Button
</BaseButton>
</span>
</BaseTooltip>
</template>