Skip to content

Tooltip Plugin

The Tooltip plugin shows popover tooltips when header or cell text overflows its container. It uses the Popover API with CSS anchor positioning for a native, consistent experience across browsers — with a JavaScript fallback for older browsers.

Tooltips appear automatically on hover. Per-column overrides let you provide custom static text or dynamic content derived from row data.

import '@toolbox-web/grid/features/tooltip';
import { queryGrid } from '@toolbox-web/grid';
import '@toolbox-web/grid/features/tooltip';
const grid = queryGrid('tbw-grid');
grid.gridConfig = {
columns: [
{ field: 'id', header: 'ID', width: 60 },
{ field: 'name', header: 'Name' },
{ field: 'email', header: 'Email Address' },
{ field: 'department', header: 'Department / Division' },
],
features: { tooltip: true },
};

Hover over truncated column headers or cell values to see tooltips. Toggle header/cell tooltips with the controls. The Job Title column demonstrates a custom headerTooltip string and a dynamic cellTooltip function.

Header tooltipsShow tooltips when header text overflows
Cell tooltipsShow tooltips when cell text overflows
OptionTypeDefaultDescription
headerbooleantrueEnable automatic tooltips on overflowing header text
cellbooleantrueEnable automatic tooltips on overflowing cell text
focusbooleantrueShow the tooltip for the focused cell during keyboard navigation. Pointer interaction is unaffected.
hideDelaynumber120Grace period in milliseconds before the tooltip hides once the pointer leaves the cell, so it can be moved onto the tooltip itself. 0 hides immediately.

Override tooltip behavior on individual columns with headerTooltip and cellTooltip:

const columns = [
// Static header tooltip
{ field: 'revenue', header: 'Rev.', headerTooltip: 'Total revenue in USD (before tax)' },
// Dynamic cell tooltip that adds context beyond the cell value
{ field: 'name', cellTooltip: (ctx) => `Hired ${new Date(ctx.row.hireDate).toLocaleDateString()}` },
// Disable tooltip for a specific column
{ field: 'actions', cellTooltip: false, headerTooltip: false },
];
PropertyTypeDescription
headerTooltipfalse | string | (ctx) => string | nullOverride header tooltip. false disables it, a string sets static text, a function returns dynamic text (return null to suppress).
cellTooltipfalse | string | (ctx) => string | nullOverride cell tooltip. Same signature as headerTooltip. The callback receives { value, row, field, column }.

The tooltip is placed above the anchor cell whenever it fits there, and drops below only when the space above the cell is too small. A directional arrow points at the anchor and flips with the placement. It supports CSS custom properties:

PropertyDefaultDescription
--tbw-tooltip-bglight-dark(#333338, #484850)Tooltip background color
--tbw-tooltip-fglight-dark(#f5f5f5, #f0f0f0)Tooltip text color
--tbw-tooltip-borderlight-dark(#222226, #6a6a72)Tooltip border and arrow color
--tbw-tooltip-shadowdrop-shadow(0 4px 4px rgba(0,0,0,.45))Tooltip shadow (a filter value, so it follows the arrow)
--tbw-tooltip-radiusvar(--tbw-border-radius)Border radius
--tbw-tooltip-max-width300pxMaximum width before the text wraps
--tbw-tooltip-arrow-size14pxSize of the arrow’s (pre-rotation) box
--tbw-tooltip-arrow-offset16pxHorizontal offset of the arrow from the left edge

The plugin satisfies WCAG 2.2 SC 1.4.13 Content on Hover or Focus:

  • Dismissible — Escape hides a visible tooltip from anywhere on the page, without moving the pointer. The key is not consumed, so it still cancels an in-progress cell edit.
  • Hoverable — the tooltip stays up for hideDelay milliseconds after the pointer leaves the cell, and indefinitely while the pointer rests on the tooltip itself. Its text is selectable, so long content can be read with a screen magnifier or copied.
  • Persistent — the tooltip is never dismissed on a timer; it hides only when the pointer or keyboard focus moves away, or on Escape.
  • Focus-triggered — arrowing onto a truncated cell shows its tooltip, so keyboard users can read content a mouse user would hover for. The anchor cell is linked to the popover via aria-describedby, and the popover carries role="tooltip".

The focus path is driven by key presses, so it only ever runs for keyboard navigation — clicking a cell with a pointer never triggers it. Set focus: false to opt out entirely (this forfeits the SC 1.4.13 “focus” path).

tbw-grid {
--tbw-tooltip-bg: #1e1e2e;
--tbw-tooltip-fg: #cdd6f4;
--tbw-tooltip-border: #45475a;
}