Tooltip
A Tooltips provides a short description of a page element or control that become visible when the target is hovered over or focussed on.
<script setup lang="ts">import { VTooltip, VButton, VIcon } from '@vonage/vivid-api-vue';</script><template> <VTooltip text="I'm a tooltip" placement="right"> <template #anchor> <VButton appearance="filled" shape="pill" aria-label="More information" ><template #icon><VIcon name="help-line" /></template ></VButton> </template> </VTooltip></template>import { registerTooltip } from '@vonage/vivid-api';
registerTooltip('your-prefix');<script type="module"> import { registerTooltip, registerButton, registerIcon } from '@vonage/vivid-api'; registerTooltip('your-prefix'); registerButton('your-prefix'); registerIcon('your-prefix');</script>
<your-prefix-tooltip text="I'm a tooltip" placement="right"> <your-prefix-button slot="anchor" shape="pill" appearance="filled" aria-label="More information"> <your-prefix-icon slot="icon" name="help-line"></your-prefix-icon> </your-prefix-button></your-prefix-tooltip>It’s best to use the anchor slot to set the anchor, but you can also use the anchor attribute. Either set it to the id of the anchor element or pass the anchor element itself.
<script setup lang="ts">import { onMounted, useTemplateRef } from 'vue';import { VButton, VIcon, VTooltip } from '@vonage/vivid-api-vue';
const secondTooltip = useTemplateRef<InstanceType<typeof VTooltip>>('tooltip2');const secondButton = useTemplateRef<InstanceType<typeof VButton>>('button2');
onMounted(() => {if (secondTooltip.value?.element) {secondTooltip.value.element.anchor = secondButton.value?.element;}});
</script>
<template> <div class="wrapper"> <VButton id="button" appearance="filled" shape="pill" aria-label="More information"> <template #icon><VIcon name="help-line" /></template> </VButton> <VTooltip anchor="button" placement="left" text="My anchor is ID" /> <VButton ref="button2" appearance="filled" shape="pill" aria-label="More information"> <template #icon><VIcon name="help-line" /></template> </VButton> <VTooltip ref="tooltip2" placement="right" text="My anchor is an HTMLElement" /> </div></template>
<style>.wrapper { display: flex; gap: 16px;}</style><div class="wrapper"> <vwc-button id="button" appearance="filled" shape="pill" aria-label="More information"> <vwc-icon slot="icon" name="help-line"></vwc-icon> </vwc-button> <vwc-tooltip anchor="button" placement="left" text="My anchor is ID"></vwc-tooltip> <vwc-button id="button2" appearance="filled" shape="pill" aria-label="More information"> <vwc-icon slot="icon" name="help-line"></vwc-icon> </vwc-button> <vwc-tooltip id="tooltip2" placement="right" text="My anchor is an HTMLElement"></vwc-tooltip></div>
<script> document.querySelector('#tooltip2').anchor = document.querySelector('#button2').id;</script>
<style> .wrapper { display: flex; gap: 16px; }</style>Tooltips need to be anchored to an element. Place the anchor element inside the anchor slot of the tooltip.
Do not use a non-interactive element (div, p, etc.) as an anchor, as the Tooltip will not be accessible to keyboard or screen reader users.
<script setup lang="ts">import { VButton, VIcon, VTooltip } from '@vonage/vivid-api-vue';</script>
<template> <VTooltip text="I'm a tooltip"> <template #anchor> <VButton shape="pill" appearance="filled" aria-label="More information"> <template #icon><VIcon name="help-line" /></template> </VButton> </template> </VTooltip></template><vwc-tooltip text="I'm a tooltip"> <vwc-button slot="anchor" shape="pill" appearance="filled" aria-label="More information"> <vwc-icon slot="icon" name="help-line"></vwc-icon> </vwc-button></vwc-tooltip>The --tooltip-max-inline-size variable sets the Tooltip’s max inline size.
- Default:
30ch
<script setup lang="ts">import { VButton, VIcon, VTooltip } from '@vonage/vivid-api-vue';</script>
<template> <VTooltip text="Turn on to receive notifications for important updates and alerts directly to your email or mobile device." class="tooltip"> <template #anchor> <VButton shape="pill" appearance="filled" aria-label="More information"> <template #icon><VIcon name="info-line" /></template> </VButton> </template> </VTooltip></template>
<style>.tooltip { --tooltip-max-inline-size: 50ch;}</style><vwc-tooltip text="Turn on to receive notifications for important updates and alerts directly to your email or mobile device." class="tooltip"> <vwc-button slot="anchor" shape="pill" appearance="filled" aria-label="More information"> <vwc-icon slot="icon" name="info-line"></vwc-icon> </vwc-button></vwc-tooltip>
<style> .tooltip { --tooltip-max-inline-size: 50ch; }</style>| Property | Type | Default | Description |
|---|---|---|---|
| anchor | string | HTMLElement | ID or direct reference to the component's anchor element. | |
| open | boolean | ||
| placement | 'top' | 'bottom' | 'left' | 'right' | 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end' | 'left-end' | 'left-start' | 'right-end' | 'right-start' | ||
| text | string | Text content of the Tooltip |
| Property | Type | Default | Description |
|---|---|---|---|
| anchor | string | HTMLElement | ID or direct reference to the component's anchor element. | |
| open | boolean | ||
| placement | 'top' | 'bottom' | 'left' | 'right' | 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end' | 'left-end' | 'left-start' | 'right-end' | 'right-start' | ||
| text | string | Text content of the Tooltip |
| Name | Description |
|---|---|
| anchor | Used to set the anchor element for the tooltip. |
| Name | Description |
|---|---|
| anchor | Used to set the anchor element for the tooltip. |