-
Notifications
You must be signed in to change notification settings - Fork 250
Tooltips in Adapt
Tooltips provide contextual information when users hover over or focus on interactive elements. They are commonly used for navigation buttons, hot graphic pins, and other icon-based controls that benefit from additional labeling.
- Tooltips appear on mouseover and keyboard focus after a 500ms delay
- Tooltips hide on mouseout, blur, click, or pressing Escape
- On mouseover, screen readers announce the tooltip text
- On keyboard focus, screen readers read the target's
aria-label(the tooltip is visually displayed but not re-announced) - Tooltips automatically reposition to stay within the viewport
Global tooltip settings are configured in course.json under the _tooltips object:
"_tooltips": {
"_isEnabled": true,
"_position": "outside bottom middle right",
"_allowTest": false
}| Attribute | Type | Description |
|---|---|---|
_isEnabled |
Boolean | Enables or disables tooltips globally. Default: true
|
_position |
String | Default position for all tooltips. See Position Syntax below. Default: "outside bottom middle right"
|
_allowTest |
Boolean | Enables test mode for development. Default: false
|
The _position attribute uses a string with up to four space-separated values:
<area> <side> <arrow position> <flow>
| Part | Values | Default | Description |
|---|---|---|---|
<area> |
outside, inside
|
outside |
Whether tooltip appears outside or inside the target element |
<side> |
top, bottom, left, right, middle
|
middle |
Which side of the target the tooltip appears on |
<arrow position> |
start, middle, end
|
middle |
Position of the arrow along the side (relative to the target) |
<flow> |
top, bottom, left, right, middle
|
middle |
Direction the tooltip extends from the arrow |
All parameters are optional. Omitted values use their defaults.
"_position": "bottom middle right"Tooltip below target, arrow in middle, content flows to the right.
"_position": "outside top start left"Tooltip above target, arrow at start of side, content flows left.
"_position": "right middle"Tooltip to the right of target, vertically centered.
-
Navigation buttons:
"outside bottom middle right"- tooltip below, flowing right -
Hot graphic pins:
"outside bottom middle middle"- tooltip below, centered
outside middle is invalid because "middle" is not a side on the outside of a target. It will be corrected to top or left depending on the flow orientation, with a console warning.
inside middle is valid, as the inside area does have a middle position.
The tooltip system is available as a singleton module:
import tooltips from 'core/js/tooltips';Registers a tooltip configuration that can be referenced by ID.
tooltips.register({
_id: 'my-button',
_isEnabled: true,
text: 'Click to continue',
disabledText: 'Complete the activity first',
_position: 'outside bottom middle right'
});Returns: A TooltipItemModel instance.
Retrieves a registered tooltip by its ID.
const tooltip = tooltips.getTooltip('my-button');
if (tooltip && tooltip.get('_isEnabled')) {
// Tooltip exists and is enabled
}Returns: A TooltipItemModel or undefined.
Displays a tooltip adjacent to a DOM element.
const tooltip = tooltips.getTooltip('my-button');
tooltips.show(tooltip, $('.my-button'));Hides a tooltip. If no argument provided, hides the most recently shown tooltip.
tooltips.hide(); // Hide last tooltip
tooltips.hide(tooltipItem); // Hide specific tooltipChecks if a tooltip is currently displayed.
if (!tooltips.isShowing(tooltip)) {
tooltips.show(tooltip, $element);
}Returns: Boolean.
When registering a tooltip, the following properties are available:
| Property | Type | Required | Description |
|---|---|---|---|
_id |
String | Yes | Unique identifier for the tooltip |
_isEnabled |
Boolean | No | Enable/disable the tooltip. Default: true
|
text |
String | No | Tooltip content (HTML supported) |
disabledText |
String | No | Text when target is disabled. Defaults to text
|
_position |
String | No | Position string. Inherits from course defaults |
_isStatic |
Boolean | No | If true, tooltip persists until explicitly hidden |
_classes |
String | No | Additional CSS classes for the tooltip |
Add tooltips to elements using the data-tooltip-id attribute:
<button class="nav__btn" data-tooltip-id="back" aria-label="Back">
<span class="icon"></span>
</button>The data-tooltip-id value must match a registered tooltip's _id.
<button
className="nav__btn"
data-tooltip-id={this.model.get('_id')}
aria-label={ariaLabel}
>
{children}
</button>Tooltip text supports template variables using {{variableName}} syntax:
Uses the target element's aria-label attribute or .aria-label child text:
{
"_id": "back-button",
"text": "{{ariaLabel}}"
}For components like Hot Graphic, you can reference item properties:
{
"_tooltip": {
"_isEnabled": true,
"text": "{{title}}"
}
}Tooltip appearance is customized through LESS variables in your theme:
@tooltip-color: rgba(0,0,0,0.85); // Background color
@tooltip-text-color: @white; // Text color
@tooltip-radius: 0.35rem; // Border radius (max 1rem)
@tooltip-offset: 0.35rem; // Arrow distance from tooltip edge (max 1rem)
@tooltip-arrow-width: 0.7rem; // Arrow width (max 1rem)
@tooltip-arrow-height: 0.35rem; // Arrow height
@tooltip-arrow: true; // Show/hide arrows globally
@tooltip-distance: 1rem; // Distance from target element
@tooltip-viewport-padding: 8px; // Padding from viewport edgesThe tooltip system includes several accessibility features:
- Tooltip container has
role="region"andaria-live="assertive" - Target elements receive
aria-describedbypointing to the tooltip - Content is announced by screen readers on mouseover
- Tab: Focus moves to tooltip targets, triggering tooltip display
- Escape: Closes the currently displayed tooltip
When a target element has aria-disabled="true" or the .is-disabled class, the tooltip displays disabledText instead of text.
Tooltips triggered by programmatic focus (e.g., after closing a popup) are suppressed to avoid unexpected announcements.
For development and debugging, enable test mode to visualize all possible tooltip positions:
"_tooltips": {
"_isEnabled": true,
"_allowTest": true
}With test mode enabled, hold Ctrl while hovering over any tooltip target to display all position combinations simultaneously.
The positioning algorithm works in stages:
-
Defaults: Calculate appropriate defaults and validate the
_positionattribute - Initial Render: Position tooltip as configured
- Overflow Check: If needed, swap sides, switch axis, or fill available space
- Edge Snapping: Snap to viewport edges as a last resort; content is truncated if necessary
The algorithm prefers the configured position but adapts when encountering viewport boundaries. Large tooltips attempt to fill the largest available space.
- Framework in Five Minutes
- Setting up Your Development Environment
- Manual Installation of the Adapt Framework
- Adapt Command Line Interface
- Common Issues
- Reporting Bugs
- Requesting Features
- Creating Your First Course
- Styling Your Course
- Configuring Your Project with config.json
- Content starts with course.json
- Course Localisation
- Compiling, testing and deploying your Adapt course
- Core Plugins in the Adapt Learning Framework
- Converting a Course from Framework Version 1 to Version 2
- Contributing to the Adapt Project
- Git Flow
- Adapt API
- Core Events
- Core Model Attributes
- Core Modules
- States and Indicators
- Right to Left (RTL) Support
- Web Security Audit
- Peer Code Review
- Plugins
- Developing Plugins
- Developer's Guide: Components
- Developer's Guide: Theme
- Making a theme editable
- Developer's Guide: Menu
- Registering a Plugin
- Semantic Version Numbers
- Migration scripts