Tooltip
Tooltips display brief contextual information when the user hovers, focuses, or taps a target element.
A tooltip's target is based on the for attribute which points to an element id.
Examples
Placement
Use the placement attribute to set the preferred placement of the tooltip.
Click Trigger
Set the trigger attribute to click to toggle the tooltip on click instead of hover.
Manual Trigger
Tooltips can be controller programmatically by setting the trigger attribute to manual. Use the open attribute to control when the tooltip is shown.
Removing Arrows
You can control the size of tooltip arrows by overriding the --wa-tooltip-arrow-size design token. To remove the arrow, use the without-arrow attribute.
To override it globally, set it in a root block in your stylesheet after the Web Awesome stylesheet is loaded.
:root { --wa-tooltip-arrow-size: 0; }
HTML in Tooltips
Use the default slot to create tooltips with HTML content. Tooltips are designed only for text and presentational elements. Avoid placing interactive content, such as buttons, links, and form controls, in a tooltip.
Setting a Maximum Width
Use the --max-width custom property to change the width the tooltip can grow to before wrapping occurs.
Importing
If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick a component manually, use one of the following snippets.
Import this component directly from the CDN:
import 'https://ka-f.webawesome.com/webawesome@0.17.0/components/tooltip/tooltip.js';
After installing Web Awesome via npm, import this component:
import '@awesome.me/webawesome/dist/components/tooltip/tooltip.js';
If you're self-hosting Web Awesome, import this component from your server:
import './webawesome/dist/components/tooltip/tooltip.js';
To import this component for React 18 or below, use the following code:
import WaTooltip from '@awesome.me/webawesome/dist/react/tooltip/index.js';
Slots
Learn more about using slots.
| Name | Description |
|---|---|
| (default) | The tooltip's default slot where any content should live. Interactive content should be avoided. |
Attributes & Properties
Learn more about attributes and properties.
| Name | Description | Reflects |
|---|---|---|
disableddisabled |
Disables the tooltip so it won't show when triggered.
Type
boolean
Default
false
|
|
distancedistance |
The distance in pixels from which to offset the tooltip away from its target.
Type
number
Default
8
|
|
hideDelayhide-delay |
The amount of time to wait before hiding the tooltip when the user mouses out.
Type
number
Default
0
|
|
openopen |
Indicates whether or not the tooltip is open. You can use this in lieu of the show/hide methods.
Type
boolean
Default
false
|
|
placementplacement |
The preferred placement of the tooltip. Note that the actual placement may vary as needed to keep the tooltip
inside of the viewport.
Type
'top'
| 'top-start'
| 'top-end'
| 'right'
| 'right-start'
| 'right-end'
| 'bottom'
| 'bottom-start'
| 'bottom-end'
| 'left'
| 'left-start'
| 'left-end'
Default
'top'
|
|
showDelayshow-delay |
The amount of time to wait before showing the tooltip when the user mouses in.
Type
number
Default
150
|
|
skiddingskidding |
The distance in pixels from which to offset the tooltip along its target.
Type
number
Default
0
|
|
triggertrigger |
Controls how the tooltip is activated. Possible options include
click, hover, focus, and manual. Multiple
options can be passed by separating them with a space. When manual is used, the tooltip must be activated
programmatically.
Type
string
Default
'hover focus'
|
|
withoutArrowwithout-arrow |
Removes the arrow from the tooltip.
Type
boolean
Default
false
|
|
Methods
Learn more about methods.
| Name | Description | Arguments |
|---|---|---|
hide() |
Hides the tooltip | |
show() |
Shows the tooltip. |
Events
Learn more about events.
| Name | Description |
|---|---|
wa-after-hide |
Emitted after the tooltip has hidden and all animations are complete. |
wa-after-show |
Emitted after the tooltip has shown and all animations are complete. |
wa-hide |
Emitted when the tooltip begins to hide. |
wa-show |
Emitted when the tooltip begins to show. |
CSS Custom Properties
Learn more about CSS custom properties.
| Name | Description |
|---|---|
--max-width |
The maximum width of the tooltip before its content will wrap.
|
CSS Parts
Learn more about CSS parts.
| Name | Description | CSS selector |
|---|---|---|
base |
The component's base wrapper, an <wa-popup> element. |
::part(base)
|
base__arrow |
The popup's exported arrow part. Use this to target the tooltip's arrow. |
::part(base__arrow)
|
base__popup |
The popup's exported popup part. Use this to target the tooltip's popup container. |
::part(base__popup)
|
body |
The tooltip's body where its content is rendered. |
::part(body)
|
Dependencies
This component automatically imports the following elements. Sub-dependencies, if any exist, will also be included in this list.