Skip to main content Sidebar
On this page
Skip to table of contents

Tooltip

<pc-tooltip> 0.4.0 experimental

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.

Edit

Demos

Placement

Use the placement attribute to set the preferred placement of the tooltip.

Edit

Click trigger

Set the trigger attribute to click to toggle the tooltip on click instead of hover.

Edit

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.

Edit

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.

Edit

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.

Edit

Set a maximum width

Use the --max-width custom property to change the width the tooltip can grow to before it wraps.

Edit

Properties

NameDescriptionReflectsDefault
contentThe tooltip’s content. If you need to display HTML, use the content slot instead.
Type: string
""
placementThe 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"
disabledDisables the tooltip so it won’t show when triggered.
Type: boolean
false
distanceThe distance in pixels from which to offset the tooltip away from its target.
Type: number
8
openIndicates whether or not the tooltip is open. You can use this instead of the show() and hide() methods.
Type: boolean
false
skiddingThe distance in pixels from which to offset the tooltip along its target.
Type: number
0
triggerControls 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 customising animations.

Slots

NameDescription
(default)The tooltip’s target element. Avoid slotting in more than one element, as subsequent elements will be ignored.
contentThe content to render in the tooltip. Alternatively, you can use the content attribute.

Learn more about using slots.

Methods

NameDescriptionArguments
show()Shows the tooltip.
hide()Hides the tooltip.

Learn more about methods.

Events

NameDescriptionEvent detail
pc-showEmitted when the tooltip starts to show.
pc-after-showEmitted when the tooltip shows and all animations are complete.
pc-hideEmitted when the tooltip starts to hide.
pc-after-hideEmitted when the tooltip hides and all animations are complete.

Learn more about events.

Custom properties

NameDescriptionDefault
--max-widthThe maximum width of the tooltip before its content will wrap.30ch
--hide-delayThe amount of time to wait before hiding the tooltip when hovering.0s
--show-delayThe amount of time to wait before showing the tooltip when hovering.0.15s

Learn more about customising custom properties.

Parts

NameDescription
baseThe component’s base wrapper, a <pc-popup> element.
base-popupThe popup’s popup part. Use this to target the tooltip’s popup container.
base-arrowThe popup’s arrow part. Use this to target the tooltip’s arrow.

Learn more about customising CSS parts.

Animations

NameDescription
tooltip.showThe animation to use when showing the tooltip.
tooltip.hideThe 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.

CDN (script tag)CDN (import)npm (import)

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.3/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.3/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:

We’d love to hear from you. Please reach out to us with any questions or enquiries you may have.

You can contact us via e‐mail at placer.coc.reports+contact@gmail.com.

We look forward to hearing from you!

Got it!
Dangerous lands

Whoa! You’ve wandered into the dangerous lands of Placer Toolkit. Version 0 is out of date and doesn’t meet EU privacy standards, including GDPR.

Want the latest powers, security and compliance? Stick with the current version of Placer Toolkit!

Yikes! Power up!

Our site is 100 % cookie‐free! We value your privacy, which is why we don’t store any cookies or personal information related to you.

Your browser history is safe from crumbs, and your data is protected, aligning with modern privacy standards like the GDPR. Enjoy your visit without a single digital cookie in sight! 🍪🚫

View our Privacy Policy for more information.

Got it!