Feedback

Tooltip

A short text hint that appears while a control is hovered or focused.

Class nameTypeDescription
tooltipplf:tooltipComponentWraps the trigger
tooltip-contentplf:tooltip-contentPartThe floating text

Touch does not open tooltips and the content cannot hold links or controls, so use a Popover for interactive content.

JavaScript

Tooltip needs JavaScript. The Full script (pelatform-ui.min.js) starts every component on page load, with no code of your own; with ESM imports, call init() yourself, as in Installation. For markup you add later, see Dynamic content.

<link rel="stylesheet" href="pelatform-ui.min.css">
<script src="pelatform-ui.min.js" defer></script>
<link rel="stylesheet" href="pelatform-ui.prefixed.min.css">
<script src="pelatform-ui.min.js" defer></script>
Attribute Purpose
data-plf-tooltip Marks the wrapper
data-plf-tooltip-trigger Optional: marks the trigger, otherwise the wrapper’s direct child without hidden: a button, link, form field or element with tabindex; disabled or aria-disabled="true" turns the tooltip off. The script adds the text to its aria-describedby unless the text only repeats the trigger’s name, so an icon-only trigger still needs an aria-label
data-plf-tooltip-content Optional: marks the text, otherwise the wrapper’s direct child with hidden; no interactive content
data-plf-placement top (default), right, bottom or left
data-plf-align start, center (default) or end
Method Behavior
PLF.Tooltip.getOrCreateInstance(element) Returns the instance, creating it for valid markup
PLF.Tooltip.getInstance(element) Returns the instance or null
instance.open() Shows the tooltip; returns false when already open, canceled, disabled or dismissed
instance.close() Hides the tooltip; returns false when already hidden or canceled
instance.destroy() Hides it without events and removes listeners
Event When
plf:tooltip:before-open Before showing; cancelable
plf:tooltip:open After showing
plf:tooltip:before-close Before hiding; cancelable
plf:tooltip:close After hiding

Each event’s detail:

Property Value
instance The Tooltip instance
reason api, trigger for the pointer or keyboard for focus and Escape
trigger The trigger when hover or focus starts or ends, otherwise null
Key Action
Tab, Shift+Tab Focusing the trigger shows the tooltip; leaving it hides the tooltip
Escape Hides the tooltip; focus stays on the trigger

React

Tooltip from @pelatform/react renders this wrapper around its trigger and text, which shows on hover and focus as the script’s does; it keeps its own state, or the application sets it with open.

Prop Values Default
placement top, right, bottom, left top
align start, center, end center
open true or false, which the application changes in onOpenChange Its own state
defaultOpen true starts shown when the application does not set open false
onOpenChange (open, reason), called when the text shows or hides: trigger for the pointer or a press, keyboard for the focus or Escape None

The parts:

Part Element
TooltipTrigger A button with type="button", which the text describes unless it repeats the button’s name; buttonClass() gives it a look
TooltipContent A span with tooltip-content and role="tooltip", holding text only

Other props are the element’s own, className and ref included.

Variable Default
--plf-tooltip-max-width 20rem, capped by the viewport
--plf-tooltip-radius Large radius
--plf-tooltip-bg --plf-color-text, an inverted fill
--plf-tooltip-color --plf-color-surface

Built with Pelatform UIv0.1.0

Components

Getting started

Foundations

Components

Actions

Data display

Navigation

Feedback

Data input

Layout

Advanced

Integrations

Blocks

Application

Authentication

Icons