The Placer Toolkit alpha has
arrived! 🎉
Plenty of changes are coming your
way—some big, some breaking, some
even nuclear! Beware the changelog…
Tooltip
<pc-tooltip> Tooltips display additional information based on a specific action.
A tooltip’s target is its first child element, so you should only wrap one element inside the tooltip. If you need the tooltip to show up for multiple elements, nest them inside a container first.
Demos#
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 controlled 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 --pc-tooltip-arrow-size custom property. To remove them, set the value to 0 as shown below.
To override it globally, set it in a root block in your styles after the Placer Toolkit styles are loaded.
:root {
--pc-tooltip-arrow-size: 0;
} HTML in tooltips#
Use the content 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.
Set a maximum width#
Use the --max-width custom property to change the width the tooltip can grow to before it wraps.
Properties#
| Name | Description | Reflects | Default |
|---|---|---|---|
content | The tooltip’s content. If you need to display HTML, use the content slot instead.Type: string |
| "" |
placement | The preferred placement of the tooltip. Note that the actual placement will vary as configured 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" |
| "top" |
disabled | Disables the tooltip so it won’t show when triggered. Type: boolean |
| false |
distance | The distance in pixels from which to offset the tooltip away from its target. Type: number |
| 8 |
open | Indicates whether or not the tooltip is open. You can use this instead of the show() and hide() methods.Type: boolean |
| false |
skidding | The distance in pixels from which to offset the tooltip along its target. Type: number |
| 0 |
trigger | 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 |
| "hover focus" |
updateComplete | A read‐only promise that resolves when the component has finished updating. | ‐ |
Learn more about attributes and properties.
Slots#
| Name | Description |
|---|---|
| (default) | The tooltip’s target element. Avoid slotting in more than one element, as subsequent elements will be ignored. |
content | The content to render in the tooltip. Alternatively, you can use the content attribute. |
Learn more about using slots.
Methods#
| Name | Description | Arguments |
|---|---|---|
show() | Shows the tooltip. | ‐ |
hide() | Hides the tooltip. | ‐ |
Learn more about methods.
Events#
| Name | Description | Event detail |
|---|---|---|
pc-show | Emitted when the tooltip starts to show. | ‐ |
pc-after-show | Emitted when the tooltip shows and all animations are complete. | ‐ |
pc-hide | Emitted when the tooltip starts to hide. | ‐ |
pc-after-hide | Emitted when the tooltip hides and all animations are complete. | ‐ |
Learn more about events.
Custom properties#
| Name | Description | Default |
|---|---|---|
--max-width | The maximum width of the tooltip before its content will wrap. | 30ch |
--hide-delay | The amount of time to wait before hiding the tooltip when hovering. | 0s |
--show-delay | The amount of time to wait before showing the tooltip when hovering. | 0.15s |
Learn more about customising custom properties.
Parts#
| Name | Description |
|---|---|
base | The component’s base wrapper, a <pc-popup> element. |
base-popup | The popup’s popup part. Use this to target the tooltip’s popup container. |
base-arrow | The popup’s arrow part. Use this to target the tooltip’s arrow. |
Learn more about customising CSS parts.
Animations#
| Name | Description |
|---|---|
tooltip.show | The animation to use when showing the tooltip. |
tooltip.hide | The animation to use when hiding the tooltip. |
Learn more about customising animations.
Importing#
If you’re using the autoloader or the standard loader, you can skip this section. But if you’re cherry picking, you can use any of the following snippets to import this component.
To manually import this component from the CDN, copy this code snippet and paste it in your HTML.
<script type="module" src="https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.1/cdn/components/tooltip/tooltip.js"></script> To manually import this component from the CDN, copy this code snippet and paste it in your JavaScript file.
import "https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.1/cdn/components/tooltip/tooltip.js"; To manually import this component from npm, copy this code snippet and paste it in your JavaScript file.
import "placer-toolkit/dist/components/tooltip/tooltip.js"; Dependencies#
This component automatically imports these components: