Skip to content

CdsTooltip

A tooltip briefly explains an interface element on hover or focus: it names an icon button, shows the full text of a truncated line, explains why an action is unavailable. It appears and disappears on its own — the user does not have to press or close anything.

Storybook GitLab Figma
Test coverage: 100% — good coverage
API in specs
55 / 55 props, events, slots and exposed members with a test
Test cases
50 unit · 7 browser
Code coverage
100% lines · 100% branches measured in v4.0.0-alpha.13
A11y (axe)
11 recommendations in 11 stories measured in v4.0.0-alpha.11

A tooltip is for a short text without interaction. A list of actions on click is the job of CdsMenu, and a dialog with a form and buttons is the job of CdsModal.

Inside the tooltip CdsOverlay does the work: it calculates the coordinates, flips the tooltip when there is not enough room near the edge of the screen, and keeps it next to the activator while scrolling. That is why the positioning and opening props of the tooltip are shared with the overlay.

Variations ​

Activator ​

The element the tooltip is attached to is set through the activator slot: the slot props (v-bind="props") put the hover handlers and the aria-describedby attribute on it. The content of the tooltip comes from the text prop or from the default slot when you need markup. If the activator is already there and you would rather not wrap it, put CdsTooltip inside it with activator="parent" — that is how the examples in “Placement” and in the scenarios below are built.

Placement ​

The location prop sets the side of the activator the tooltip appears on: top by default, bottom, left, right — and their combinations with an alignment (top left, bottom right). If there is not enough room, the tooltip flips to the opposite side by itself. The offset prop tunes the distance to the activator.

Arrow ​

The arrow points at the activator and follows the actual position of the tooltip — including after an automatic flip near the edge of the screen. The hide-arrow prop hides it.

Opening behavior ​

By default the tooltip opens on hover and on keyboard focus, with no delay. The open-delay and close-delay props add a pause — the tooltip does not blink when the cursor passes by. The open-on-click prop together with :open-on-hover="false" switches opening to a click.

Controlling the display ​

v-model opens and closes the tooltip from code — this is how you show it in response to interface events, not only on hover.

Guidelines ​

Scenarios ​

Icon button bar ​

A tooltip gives an icon button back the name of its action. CdsTooltip lives inside the button with activator="parent" — there is no need to wrap the markup. aria-label is still required: the tooltip appears on hover, while the name of the action must be available at all times.

Truncated text ​

When space is limited, long titles are cut off with truncate — the tooltip shows the full text on hover over the line. The same text prop serves both as the content of the line and as the content of the tooltip.

Unavailable action ​

A disabled button should not stay silent — the tooltip explains why the action is closed. A button with disabled has its mouse events turned off, so the tooltip is attached to a wrapper through activator="parent". The disabled prop of the tooltip itself turns it off as soon as the action becomes available.

Confirming an action ​

A tooltip can confirm an instant action when there is no room for a message — copying to the clipboard, for example. The display is driven by v-model on click, and :open-on-hover="false" keeps the tooltip from opening on a plain hover. After a second and a half a timer closes it on its own.

Onboarding ​

The interactive prop allows interaction with the content: hovering the tooltip does not close it, and the elements inside stay clickable. So that the pointer can cross the gap from the activator to the tooltip, an interactive tooltip closes after a 250 ms delay; an explicit close-delay overrides it. Together with open-on-click and v-model this makes an onboarding tooltip: a “Learn more” link and a button that closes the tooltip. The width prop keeps the text width comfortable to read.

API ​

Props

NameTypeDefaultDescription
activator(string & {}) | Element | "parent" | ComponentPublicInstance | undefined—The element that activates the component
activatorPropsRecord<string, any> | undefined{}Props for the activator element
attachstring | boolean | Element | undefined—Sets the DOM element the overlay content is moved to. It accepts a direct element reference, a querySelector string, or true to disable moving. By default the body element is used. Changing this prop is usually not recommended except for edge cases: the default positioning algorithm handles most scenarios better than it can without moving, and unexpected behavior may appear if the menu ends up being a child of its activator.
closeDelaystring | number | undefined—Delay in milliseconds before the component closes. Works only together with open-on-hover.
closeOnBackboolean | undefinedfalseCloses the overlay content when the browser Back button is pressed or $router.back() is called, cancelling the original navigation. persistent overlays cancel the navigation and animate as if they were clicked outside instead of closing.
closeOnContentClickboolean | undefined—Hide the component on a click on the content
colorstring | undefined—Background color of the tooltip.
containedboolean | undefined—Limits the size of the component and of its grid to the offset parent. Implies the absolute and attach props. (Note: the parent element must have position: relative.)
contentClassany—Applies a custom class to the content element. This is handy because the content is moved to the beginning of the cds-app component (unless attach is set) and cannot be selected with classes passed to the component directly.
contentPropsany—Applies custom props to the moved content
disabledboolean | null | undefinednullDisabled state
eagerboolean | undefinedtrueRenders the content of the component right away. Useful when you have content that is not in the DOM but has to be indexed for SEO.
heightstring | number | undefined—Component height
hideArrowboolean | undefined—Hides the arrow pointing at the activator. The arrow is shown by default.
idstring | undefined—Unique id that links the tooltip to its activator. Generated automatically when omitted.
interactiveboolean | undefined—Allows interaction with the tooltip content: hovering the content does not close it. The tooltip closes after a 250 ms delay unless closeDelay is set, so the pointer can cross the gap between the activator and the tooltip.
locationAnchor | undefined'top'Sets the anchor point used to position the component, aligning it horizontally, vertically or in both directions
locationStrategy"static" | "connected" | LocationStrategyFunction | undefined'connected'Sets the way the overlay content is positioned. By default static is used, which centers the content in its container. Use connected to attach the content to the activator element.
maxHeightstring | number | undefined—Maximum component height
maxWidthstring | number | undefined—Maximum component width
minHeightstring | number | undefined—Minimum component height
minWidthstring | number | undefined0Minimum component width
modelValueboolean | undefined—The v-model value of the component. If the component supports the multiple prop, an empty array is used by default.
noClickAnimationboolean | undefined—Disables the bounce effect on a click outside the content element when persistent is set.
offsetstring | number | number[] | undefined10Increases the distance to the target. If two numbers are passed, the second one shifts the anchor sideways, away from the target.
opacitystring | number | undefined—Opacity of the scrim element. Applies only when scrim=true.
openDelaystring | number | undefined—Delay in milliseconds before the component opens. Works only together with open-on-hover.
openOnClickboolean | undefinedfalseShow the component on a click on the activator
openOnFocusboolean | undefined—Show the component when the activator gets focus
openOnHoverboolean | undefinedtrueShow the component on hover over the activator
originAnchor | "auto" | "overlap" | undefined'auto'Sets the anchor point of the overlay content that is aligned with the location anchor of the target. With "auto" the opposite side of the location point is used. With "overlap" the same anchor point is used, so the overlay overlaps the target. It also sets the CSS transform-origin property for the enter/leave transitions.
persistentboolean | undefined—A click outside the element or the Esc key does not close it.
scrimstring | boolean | undefinedfalseBackdrop shown while the overlay is active. Accepts true/false to toggle the backdrop and a string to set its color.
scrollStrategy"none" | "close" | "block" | "reposition" | ScrollStrategyFunction | undefined'reposition'Strategy applied when the component is active and the user scrolls the page.
stickToTargetboolean | undefined—Lets the overlay content go off screen while scrolling.
target(string & {}) | Element | "parent" | ComponentPublicInstance | "cursor" | [x: number, y: number] | undefined—When locationStrategy is set to "connected", specify the element or the array of x, y coordinates the overlay is positioned against. By default the activator element is used.
textstring | undefined—Text of the tooltip. Used when the default slot is not passed.
themestring | undefined—Component theme
transitionstring | boolean | (TransitionProps & { component?: Component | undefined; }) | null | undefinednullTransition animation
viewportMarginstring | number | undefined12Sets a custom viewport margin for the overlay content
widthstring | number | undefined—Component width
zIndexstring | number | undefined2000The z-index value of the component.

Events

NameTypeDescription
update:modelValue[value: boolean]Fires when the tooltip is shown or hidden. Passes the new visibility state

Slots

NameTypeDescription
activator{ isActive: boolean; props: Record<string, any>; targetRef: TemplateRef; }Slot for the element that acts as the activator of the overlay.
default{ isActive: Ref<boolean, boolean>; }Slot for the overlay content.

Exposed

NameTypeDescription
activatorElHTMLElement | undefinedThe DOM element of the activator.
activatorRefTemplateRefTemplate ref for assigning the activator manually.
animateClick() => voidRuns the bounce animation of the content — the same as on a click outside a persistent overlay.
contentElHTMLElement | undefinedThe DOM element of the overlay content.
globalTopbooleanWhether the overlay is the top one in the global stack of open overlays.
rootElHTMLElement | undefinedThe root DOM element of the overlay.
scrimElHTMLElement | undefinedThe DOM element of the scrim that dims the page.
targetElHTMLElement | undefinedThe DOM element of the positioning target.
targetRefTemplateRefTemplate ref for assigning the positioning target manually.
updateLocation((e: Event) => void) | undefinedRecalculates the position of the content relative to the target.