Data display

Tooltip

A short hint shown above an element on hover and on keyboard focus. CSS for showing it; in the browser, Escape hides it.

JxTooltip import 'package:jx_cli/ui.dart' Available since 0.0.2

Preview

Press Escape to hide the hint.

When to use it

  • Naming an icon button visually.
  • A short extra detail that is not essential.

Minimal example

Dart
JxTooltip(
  id: 'copy-tip',
  text: 'Copy the link',
  child: JxButton(attributes: JxTooltip.describedBy('copy-tip'), [.text('Copy')]),
)

Complete example

A full Jaspr component you can paste into a project.

Dart
import 'package:jaspr/dom.dart';
import 'package:jaspr/jaspr.dart';
import 'package:jx_cli/ui.dart';

/// An icon-only button: the accessible name is on the button, the tooltip
/// shows the same words to sighted users.
class DeleteIconButton extends StatelessComponent {
  const DeleteIconButton({required this.onDelete, super.key});

  final VoidCallback onDelete;

  @override
  Component build(BuildContext context) {
    return JxTooltip(
      text: 'Delete',
      child: JxButton(
        variant: JxButtonVariant.ghost,
        attributes: const {'aria-label': 'Delete'},
        onClick: onDelete,
        [
          svg(viewBox: '0 0 24 24', classes: 'w:4 h:4', attributes: const {'fill': 'none', 'stroke': 'currentColor', 'stroke-width': '2', 'aria-hidden': 'true'}, [
            path(d: 'M3 6h18M8 6V4h8v2M6 6l1 14h10l1-14', []),
          ]),
        ],
      ),
    );
  }
}

Properties

Property Type Default Description
text String required Hint text, one short line.
child Component required The element the hint belongs to; it should be focusable.
id String? null Id of the bubble, to reference with JxTooltip.describedBy(id) .
classes String? null Extra JX classes, appended after the component classes.

Related types

Name Role
JxTooltip.describedBy(id) Attributes {'aria-describedby': id} for the described element.

Customizing

  • Pass classes to add or override utilities: they come last, so classes: 'w:full' wins over the default width.

Accessibility

  • It appears on hover and on keyboard focus inside the wrapper (group-focus-within:).
  • The bubble has role="tooltip". Give it an id and pass JxTooltip.describedBy(id) to the child so screen readers read it.
  • Give icon-only buttons their own aria-label.
  • In the browser, Escape hides the bubble until the pointer or the focus leaves (WCAG 1.4.13).

Limitations

  • Rendered on the server alone, Escape does nothing: keep essential information out of tooltips.
  • Always placed above the element; it can be clipped by a parent with ov:hidden.
  • No touch trigger: on phones it shows only while the element has focus.