Tooltip
A tooltip component that displays text when hovering over trigger content.
Using Tooltip
You rarely need to use the Tooltip component directly, as visual components support three properties,
tootip
, tooltipMarkdown
, and tooltipOptions
respectively. When you utilize the tooltip
property with a visual component, hovering over that component displays the associated text.The tooltip
property
<App>
<CHStack height="100px" verticalAlignment="center" >
<Button
label="Hover the mouse over me!"
tooltip="I'm a hovered!"
>
</Button>
</CHStack>
</App>
Example: using the tooltip property
<App>
<CHStack height="100px" verticalAlignment="center" >
<Button
label="Hover the mouse over me!"
tooltip="I'm a hovered!"
>
</Button>
</CHStack>
</App>
The tooltipMarkdown
property
The
tooltipMarkdown
property allows you to use the tooltip with markdown syntax.<App>
<VStack height="80px" width="fit-content">
<Card
title="Tooltip with markdown"
tooltipMarkdown="This *example* uses `toolTipMarkdown`"
tooltipOptions="right"
/>
</VStack>
</App>
Example: using the tooltipMarkdown property
<App>
<VStack height="80px" width="fit-content">
<Card
title="Tooltip with markdown"
tooltipMarkdown="This *example* uses `toolTipMarkdown`"
tooltipOptions="right"
/>
</VStack>
</App>
The tooltipOptions
property
The tooltip provides several options (see the properties of this component), influencing its behavior and appearance. You can set the
tooltipOptions
property to define these options.For example, the following example positions the tooltip to the right, making it appear somewhat distant from the component.
<App>
<CHStack height="100px" verticalAlignment="center" >
<Button
label="Hover the mouse over me!"
tooltip="I'm hovered"
tooltipOptions="right; sideOffset: 32"
>
</Button>
</CHStack>
</App>
Example: using the tooltipOptions property
<App>
<CHStack height="100px" verticalAlignment="center" >
<Button
label="Hover the mouse over me!"
tooltip="I'm hovered"
tooltipOptions="right; sideOffset: 32"
>
</Button>
</CHStack>
</App>
You can define
tooltipOptions
as a string or as an object. In the latter case, the object declares name and value pairs describing the visual options:<App>
<CHStack height="100px" verticalAlignment="center" >
<Button
label="Hover the mouse over me!"
tooltip="My options use an object"
tooltipOptions="{{ showArrow: false, side: 'bottom', align: 'start' }}"
>
</Button>
</CHStack>
</App>
Example: tooltipOptions as an object
<App>
<CHStack height="100px" verticalAlignment="center" >
<Button
label="Hover the mouse over me!"
tooltip="My options use an object"
tooltipOptions="{{ showArrow: false, side: 'bottom', align: 'start' }}"
>
</Button>
</CHStack>
</App>
The string form of
tooltipOptions
is composed of names or name and value pairs separated by semicolons. The properties that allow enumerations (such as side
or align
) can be set with a name representing a single value. Properties with boolean values can use the property name to represent the true
value, or the property name prefixed with an exclamation mark to signify a false
value. Numeric values are separated from the property name by a colon, and they do not use units. Here are a few examples:<App>
<VStack height="100px" horizontalAlignment="center" gap="3rem">
<Card
title="Tooltip to the left with 800ms delay"
tooltip="I'm a Tooltip"
tooltipOptions="left; delayDuration: 800; !showArrow" />
<HStack>
<Icon
name="email"
width="48px"
height="48px"
tooltipMarkdown="**Tooltip** to the bottom with no arrows, aligned left"
tooltipOptions="bottom; !showArrow; start" />
<Icon
name="phone"
width="48px"
height="48px"
tooltipMarkdown="*Tooltip* to the bottom with arrows, 28 pixels away"
tooltipOptions="bottom; showArrow; sideOffset: 28" />
</HStack>
</VStack>
</App>
Example: tooltipOptions as a string
<App>
<VStack height="100px" horizontalAlignment="center" gap="3rem">
<Card
title="Tooltip to the left with 800ms delay"
tooltip="I'm a Tooltip"
tooltipOptions="left; delayDuration: 800; !showArrow" />
<HStack>
<Icon
name="email"
width="48px"
height="48px"
tooltipMarkdown="**Tooltip** to the bottom with no arrows, aligned left"
tooltipOptions="bottom; !showArrow; start" />
<Icon
name="phone"
width="48px"
height="48px"
tooltipMarkdown="*Tooltip* to the bottom with arrows, 28 pixels away"
tooltipOptions="bottom; showArrow; sideOffset: 28" />
</HStack>
</VStack>
</App>
Using the Tooltip component
Instead of using the tooltip-related properties, you can wrap the component into a
Tooltip
:<App>
<VStack height="100px" horizontalAlignment="center">
<Tooltip side="bottom" markdown="This *example* uses a `Tooltip` component">
<Card title="Card 1: within a Tooltip" />
<Card title="Card 2: within the same Tooltip" />
</Tooltip>
</VStack>
</App>
Example: Using the Tooltip component
<App>
<VStack height="100px" horizontalAlignment="center">
<Tooltip side="bottom" markdown="This *example* uses a `Tooltip` component">
<Card title="Card 1: within a Tooltip" />
<Card title="Card 2: within the same Tooltip" />
</Tooltip>
</VStack>
</App>
Using a Tooltip template
You can specify tooltips that you could not otherwise do with the
text
or markdown
properties.<App>
<VStack height="100px" horizontalAlignment="center">
<Tooltip side="bottom">
<property name="tooltipTemplate">
<HStack>
<Stack width="24px" height="24px" backgroundColor="purple" />
<H2>This is a tooltip</H2>
</HStack>
</property>
<Card title="I have a templated Tooltip!" />
</Tooltip>
</VStack>
</App>
Example: Using a tooltipTemplate
<App>
<VStack height="100px" horizontalAlignment="center">
<Tooltip side="bottom">
<property name="tooltipTemplate">
<HStack>
<Stack width="24px" height="24px" backgroundColor="purple" />
<H2>This is a tooltip</H2>
</HStack>
</property>
<Card title="I have a templated Tooltip!" />
</Tooltip>
</VStack>
</App>
Properties
align
(default: "center")
The preferred alignment against the trigger
Available values:
start
, center
(default), end
alignOffset
(default: 0)
An offset in pixels from the 'start' or 'end' alignment options
avoidCollisions
(default: true)
When true, overrides the side and align preferences to prevent collisions with boundary edges
defaultOpen
(default: false)
The open state of the tooltip when it is initially rendered
delayDuration
(default: 700)
The duration from when the mouse enters a tooltip trigger until the tooltip opens (in ms)
markdown
The markdown content to display in the tooltip
showArrow
(default: false)
Whether to show the arrow pointing to the trigger element
side
(default: "top")
The preferred side of the trigger to render against when open
Available values:
top
(default), right
, bottom
, left
sideOffset
(default: 4)
The distance in pixels from the trigger
skipDelayDuration
(default: 300)
How much time a user has to enter another trigger without incurring a delay again (in ms)
text
The text content to display in the tooltip
tooltipTemplate
The template for the tooltip content
Events
This component does not have any events.
Exposed Methods
This component does not expose any methods.
Styling
Theme Variables
Variable | Default Value (Light) | Default Value (Dark) |
---|---|---|
animation-Tooltip | cubic-bezier(0.16, 1, 0.3, 1) | cubic-bezier(0.16, 1, 0.3, 1) |
animationDuration-Tooltip | 400ms | 400ms |
backgroundColor-Tooltip | $color-surface-0 | $color-surface-200 |
border-Tooltip | none | none |
borderBottom-Tooltip | none | none |
borderBottomColor-Tooltip | none | none |
borderBottomStyle-Tooltip | none | none |
borderBottomWidth-Tooltip | none | none |
borderColor-Tooltip | none | none |
borderEndEndRadius-Tooltip | none | none |
borderEndStartRadius-Tooltip | none | none |
borderHorizontal-Tooltip | none | none |
borderHorizontalColor-Tooltip | none | none |
borderHorizontalStyle-Tooltip | none | none |
borderHorizontalWidth-Tooltip | none | none |
borderLeft-Tooltip | none | none |
color-Tooltip | none | none |
borderLeftStyle-Tooltip | none | none |
borderLeftWidth-Tooltip | none | none |
borderRadius-Tooltip | 4px | 4px |
borderRight-Tooltip | none | none |
color-Tooltip | none | none |
borderRightStyle-Tooltip | none | none |
borderRightWidth-Tooltip | none | none |
borderStartEndRadius-Tooltip | none | none |
borderStartStartRadius-Tooltip | none | none |
borderStyle-Tooltip | none | none |
borderTop-Tooltip | none | none |
borderTopColor-Tooltip | none | none |
borderTopStyle-Tooltip | none | none |
borderTopWidth-Tooltip | none | none |
borderHorizontal-Tooltip | none | none |
borderVerticalColor-Tooltip | none | none |
borderVerticalStyle-Tooltip | none | none |
borderVerticalWidth-Tooltip | none | none |
borderWidth-Tooltip | none | none |
boxShadow-Tooltip | hsl(206 22% 7% / 35%) 0px 10px 38px -10px, hsl(206 22% 7% / 20%) 0px 10px 20px -15px | hsl(206 22% 7% / 35%) 0px 10px 38px -10px, hsl(206 22% 7% / 20%) 0px 10px 20px -15px |
fill-arrow-Tooltip | $color-surface-200 | $color-surface-200 |
fontSize-Tooltip | 15px | 15px |
lineHeight-Tooltip | 1 | 1 |
padding-Tooltip | none | none |
paddingBottom-Tooltip | 10px | 10px |
paddingHorizontal-Tooltip | none | none |
paddingLeft-Tooltip | 15px | 15px |
paddingRight-Tooltip | 15px | 15px |
paddingTop-Tooltip | 10px | 10px |
paddingVertical-Tooltip | none | none |
stroke-arrow-Tooltip | $color-surface-200 | $color-surface-200 |
strokeWidth-arrow-Tooltip | 0 | 0 |
textColor-Tooltip | $textcolor-primary | $textcolor-primary |