Tooltip
Displays a popup label to describe an element.
The tooltip component improves the interface accessibility by providing context to interactive elements. It uses AlpineJs Anchor for precise positioning and handles ARIA attributes automatically.
Reference
The tooltip partial accepts a dictionary with the following terms:
- label
"label" "A slice of Pizza"— (string, required)- The text content of the tooltip.
Installation
The tooltip component is disabled by default to save resources.
Uncomment the import in the following files:
JavaScript
Create the Alpine module:
Import and register it in main.js:
Hugo Partial
Create the partial file:
CSS Styling
Create the CSS component:
Import it in your main Tailwind file:
Usage
To use a tooltip, you must apply the Alpine directives to the parent (trigger) and place the partial inside it.
Alpine directives
x-data="ksTooltip"— Initializes logicx-id="['ks-tooltip']"— Generates unique IDx-bind="trigger"— Handles events (hover/focus)
Tips & tricks
Internationalization (i18n)
Avoid hardcoding strings. Use Hugo’s i18n function to make your UI multilingual.
Accessibility
The component is engineered to meet WCAG 2.2 SC: 1.4.13 (Opens in a new tab) :
- Automatic Association: Generates a unique ID and binds
aria-describedbyto the parent trigger. - Hoverable (Safe Triangle): Implements a logical “bridge”. Users can move their cursor from the trigger into the tooltip content to select text without the tooltip disappearing.
- Dismissible: Users can press the
Escapekey to close the tooltip immediately without moving focus. - Persistent: The content does not disappear on its own while the user is interacting with the trigger or the tooltip itself.
- Keyboard Support: Full visibility support for
focusandblurevents on the parent trigger.