Usage
Use a Button or any other component in the default slot of the Tooltip.
App
component which uses the TooltipProvider
component from Reka UI.Text
Use the text
prop to set the content of the Tooltip.
<template>
<UTooltip text="Open on GitHub">
<UButton label="Open" color="neutral" variant="subtle" />
</UTooltip>
</template>
Kbds
Use the kbds
prop to render Kbd components in the Tooltip.
<template>
<UTooltip text="Open on GitHub" :kbds="['meta', 'G']">
<UButton label="Open" color="neutral" variant="subtle" />
</UTooltip>
</template>
meta
that displays as ⌘
on macOS and Ctrl
on other platforms.Delay
Use the delay-duration
prop to change the delay before the Tooltip appears. For example, you can make it appear instantly by setting it to 0
.
<template>
<UTooltip :delay-duration="0" text="Open on GitHub">
<UButton label="Open" color="neutral" variant="subtle" />
</UTooltip>
</template>
tooltip.delayDuration
option in the App
component.Content
Use the content
prop to control how the Tooltip content is rendered, like its align
or side
for example.
<template>
<UTooltip
:content="{
align: 'center',
side: 'bottom',
sideOffset: 8
}"
text="Open on GitHub"
>
<UButton label="Open" color="neutral" variant="subtle" />
</UTooltip>
</template>
Arrow
Use the arrow
prop to display an arrow on the Tooltip.
<template>
<UTooltip arrow text="Open on GitHub">
<UButton label="Open" color="neutral" variant="subtle" />
</UTooltip>
</template>
Disabled
Use the disabled
prop to disable the Tooltip.
<template>
<UTooltip disabled text="Open on GitHub">
<UButton label="Open" color="neutral" variant="subtle" />
</UTooltip>
</template>
Examples
Control open state
You can control the open state by using the default-open
prop or the v-model:open
directive.
<script setup lang="ts">
const open = ref(false)
defineShortcuts({
o: () => open.value = !open.value
})
</script>
<template>
<UTooltip v-model:open="open" text="Open on GitHub">
<UButton label="Open" color="neutral" variant="subtle" />
</UTooltip>
</template>
defineShortcuts
, you can toggle the Tooltip by pressing O.API
Props
Prop | Default | Type |
---|---|---|
text |
The text content of the tooltip. | |
kbds |
The keyboard keys to display in the tooltip.
| |
content |
|
The content of the tooltip. |
arrow |
|
Display an arrow alongside the tooltip. |
portal |
|
Render the tooltip in a portal. |
defaultOpen |
The open state of the tooltip when it is initially rendered. Use when you do not need to control its open state. | |
open |
The controlled open state of the tooltip. | |
delayDuration |
|
Override the duration given to the |
disableHoverableContent |
Prevents Tooltip.Content from remaining open when hovering. Disabling this has accessibility consequences. Inherits from Tooltip.Provider. | |
disableClosingTrigger |
|
When |
disabled |
|
When |
ignoreNonKeyboardFocus |
|
Prevent the tooltip from opening if the focus did not come from
the keyboard by matching against the |
ui |
|
Slots
Slot | Type |
---|---|
default |
|
content |
|
Emits
Event | Type |
---|---|
update:open |
|
Theme
export default defineAppConfig({
ui: {
tooltip: {
slots: {
content: 'flex items-center gap-1 bg-[var(--ui-bg)] text-[var(--ui-text-highlighted)] shadow-sm rounded-[var(--ui-radius)] ring ring-[var(--ui-border)] h-6 px-2 py-1 text-xs select-none data-[state=delayed-open]:animate-[scale-in_100ms_ease-out] data-[state=closed]:animate-[scale-out_100ms_ease-in] pointer-events-auto',
arrow: 'fill-[var(--ui-border)]',
text: 'truncate',
kbds: "hidden lg:inline-flex items-center shrink-0 gap-0.5 before:content-['·'] before:me-0.5",
kbdsSize: 'sm'
}
}
}
})
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nuxt/ui/vite'
export default defineConfig({
plugins: [
vue(),
ui({
ui: {
tooltip: {
slots: {
content: 'flex items-center gap-1 bg-[var(--ui-bg)] text-[var(--ui-text-highlighted)] shadow-sm rounded-[var(--ui-radius)] ring ring-[var(--ui-border)] h-6 px-2 py-1 text-xs select-none data-[state=delayed-open]:animate-[scale-in_100ms_ease-out] data-[state=closed]:animate-[scale-out_100ms_ease-in] pointer-events-auto',
arrow: 'fill-[var(--ui-border)]',
text: 'truncate',
kbds: "hidden lg:inline-flex items-center shrink-0 gap-0.5 before:content-['·'] before:me-0.5",
kbdsSize: 'sm'
}
}
}
})
]
})