Tooltip
xph0000xUso
Utilice un Button o cualquier otro componente en la ranura predeterminada de la información sobre herramientas.
<template>
<UTooltip text="Open on GitHub">
<UButton label="Open" color="neutral" variant="subtle" />
</UTooltip>
</template>App que utiliza el componente TooltipProvider de Reka UI.App prop tooltip para ver cómo configurar la información sobre herramientas a nivel mundial.Text (Edición española)
Utilice el prop text para establecer el contenido de la información sobre herramientas.
<template>
<UTooltip text="Open on GitHub">
<UButton label="Open" color="neutral" variant="subtle" />
</UTooltip>
</template>kbds (Edición española)
Utilice el prop kbds para representar los componentes Kbd en la información sobre herramientas.
<template>
<UTooltip text="Open on GitHub" :kbds="['meta', 'G']">
<UButton label="Open" color="neutral" variant="subtle" />
</UTooltip>
</template>meta que se muestra como ⌘ en macOS y Ctrl en otras plataformas.Delay (Edición española)
Utilice el prop delay-duration para cambiar el retardo antes de que aparezca la información sobre herramientas. Por ejemplo, puede hacer que aparezca instantáneamente configurándolo en 0.
<template>
<UTooltip :delay-duration="0" text="Open on GitHub">
<UButton label="Open" color="neutral" variant="subtle" />
</UTooltip>
</template>tooltip.delayDuration en el componente App.Contenido
Utilice el prop content para controlar cómo se representa el contenido de la información de herramientas, como su align o side, por ejemplo.
tooltip.content en el componente App.<template>
<UTooltip
:content="{
align: 'center',
side: 'bottom',
sideOffset: 8
}"
text="Open on GitHub"
>
<UButton label="Open" color="neutral" variant="subtle" />
</UTooltip>
</template>Flecha
Utilice el accesorio arrow para mostrar una flecha en la información sobre herramientas.
<template>
<UTooltip arrow text="Open on GitHub">
<UButton label="Open" color="neutral" variant="subtle" />
</UTooltip>
</template>Desactivado
Utilice el prop disabled para desactivar la información sobre herramientas.
<template>
<UTooltip disabled text="Open on GitHub">
<UButton label="Open" color="neutral" variant="subtle" />
</UTooltip>
</template>Ejemplos
Control estado abierto
Puede controlar el estado abierto usando la prop default-open o la directiva v-model:open.
<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>
<script setup lang="ts">
import { ref } from 'vue'
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, puede alternar la información sobre herramientas presionando: kbd{value="O"}.Con el cursor siguiente
Puede hacer que la información sobre herramientas siga el cursor al pasar el cursor sobre un elemento utilizando la prop reference:
<script setup lang="ts">
const open = ref(false)
const anchor = ref({ x: 0, y: 0 })
const reference = computed(() => ({
getBoundingClientRect: () =>
({
width: 0,
height: 0,
left: anchor.value.x,
right: anchor.value.x,
top: anchor.value.y,
bottom: anchor.value.y,
...anchor.value
} as DOMRect)
}))
</script>
<template>
<UTooltip
:open="open"
:reference="reference"
:content="{ side: 'top', sideOffset: 16, updatePositionStrategy: 'always' }"
>
<div
class="flex items-center justify-center rounded-md border border-dashed border-accented text-sm aspect-video w-72"
@pointerenter="open = true"
@pointerleave="open = false"
@pointermove="(ev: PointerEvent) => {
anchor.x = ev.clientX
anchor.y = ev.clientY
}"
>
Hover me
</div>
<template #content>
{{ anchor.x.toFixed(0) }} - {{ anchor.y.toFixed(0) }}
</template>
</UTooltip>
</template>
<script setup lang="ts">
import { ref, computed } from 'vue'
const open = ref(false)
const anchor = ref({ x: 0, y: 0 })
const reference = computed(() => ({
getBoundingClientRect: () =>
({
width: 0,
height: 0,
left: anchor.value.x,
right: anchor.value.x,
top: anchor.value.y,
bottom: anchor.value.y,
...anchor.value
} as DOMRect)
}))
</script>
<template>
<UTooltip
:open="open"
:reference="reference"
:content="{ side: 'top', sideOffset: 16, updatePositionStrategy: 'always' }"
>
<div
class="flex items-center justify-center rounded-md border border-dashed border-accented text-sm aspect-video w-72"
@pointerenter="open = true"
@pointerleave="open = false"
@pointermove="(ev: PointerEvent) => {
anchor.x = ev.clientX
anchor.y = ev.clientY
}"
>
Hover me
</div>
<template #content>
{{ anchor.x.toFixed(0) }} - {{ anchor.y.toFixed(0) }}
</template>
</UTooltip>
</template>
API
Props (accesorios)
| Prop | Default | Type |
|---|---|---|
text | stringThe text content of the tooltip. | |
kbds | (string | undefined)[] | KbdProps[]The keyboard keys to display in the tooltip. | |
content | { side: 'bottom', sideOffset: 8, collisionPadding: 8 } | TooltipContentProps & Partial<EmitsToProps<TooltipContentImplEmits>>The content of the tooltip. Inherits from the |
arrow | false | boolean | TooltipArrowProps Display an arrow alongside the tooltip.
|
portal | true | string | false | true | HTMLElementRender the tooltip in a portal. |
reference | Element | VirtualElementThe reference (or anchor) element that is being referred to for positioning. If not provided will use the current component as anchor. | |
defaultOpen | boolean The open state of the tooltip when it is initially rendered. Use when you do not need to control its open state. | |
open | boolean The controlled open state of the tooltip. | |
delayDuration | 700 | numberOverride the duration given to the |
disableHoverableContent | boolean Prevents Tooltip.Content from remaining open when hovering. Disabling this has accessibility consequences. Inherits from Tooltip.Provider. | |
disableClosingTrigger | false | boolean When |
disabled | false | boolean When |
ignoreNonKeyboardFocus | false | boolean Prevent the tooltip from opening if the focus did not come from
the keyboard by matching against the |
ui | { content?: SlotClass; arrow?: SlotClass; text?: SlotClass; kbds?: SlotClass; kbdsSize?: SlotClass; } |
Slots (Edición española)
| Slot | Type |
|---|---|
default | { open: boolean; } |
content | { ui: object; } |
Emisiones
| Event | Type |
|---|---|
update:open | [value: boolean] |
Temas
export default defineAppConfig({
ui: {
tooltip: {
slots: {
content: 'flex items-center gap-1 bg-default text-highlighted shadow-sm rounded-sm ring ring-default h-6 px-2.5 py-1 text-xs select-none data-[state=delayed-open]:animate-[scale-in_100ms_var(--ease-out)] data-[state=closed]:animate-[scale-out_100ms_var(--ease-out)] origin-(--reka-tooltip-content-transform-origin) pointer-events-auto',
arrow: 'fill-bg stroke-default',
text: 'truncate',
kbds: "hidden lg:inline-flex items-center shrink-0 gap-0.5 not-first-of-type:before:content-['·'] not-first-of-type: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-default text-highlighted shadow-sm rounded-sm ring ring-default h-6 px-2.5 py-1 text-xs select-none data-[state=delayed-open]:animate-[scale-in_100ms_var(--ease-out)] data-[state=closed]:animate-[scale-out_100ms_var(--ease-out)] origin-(--reka-tooltip-content-transform-origin) pointer-events-auto',
arrow: 'fill-bg stroke-default',
text: 'truncate',
kbds: "hidden lg:inline-flex items-center shrink-0 gap-0.5 not-first-of-type:before:content-['·'] not-first-of-type:before:me-0.5",
kbdsSize: 'sm'
}
}
}
})
]
})