Skip to content
Alea0.1

Overlays

Tooltip

A short hint on hover and keyboard focus.

Ant Design: Tooltip

import { TooltipTrigger, Tooltip } from '@alea/ui';

Examples

Tooltip

On hover after a short delay, and right away on keyboard focus.

On text and links

A tooltip explains, it never holds the only copy of something important.

Contrast must be at least 4.5:1 for body text.

Props

Tooltip props

A short hint on hover or keyboard focus. Not for anything the user must read to act.

PropTypeDefaultDescription
aria-labelstring-Defines a string value that labels the current element. (React Aria)
classNameClassNameOrFunction<TooltipRenderProps>-The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. A function may be provided to compute the class based on component state. (React Aria)
defaultOpenboolean-Whether the overlay is open by default (uncontrolled). (React Aria)
isOpenboolean-Whether the element is rendered. (React Aria)
offsetnumber8The additional offset applied along the main axis between the element and its anchor element. (React Aria)
onOpenChange((isOpen: boolean) => void)-Handler that is called when the overlay's open state changes. (React Aria)
placement"start" | "end" | "bottom" | "top" | "bottom left" | "bottom right" | "bottom start" | "bottom end" | "top left" | "top right" | "top start" | "top end" | "l…-The placement of the tooltip with respect to the trigger. (React Aria)
styleStyleOrFunction<DisclosureGroupRenderProps>-The inline [style](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) for the element. A function may be provided to compute the style based on component state. (React Aria)

TooltipTrigger props

Wraps a focusable trigger and its Tooltip. Default delay 600 ms, 0 when moving between tooltips.

PropTypeDefaultDescription
closeDelaynumber200The delay time for the tooltip to close. [See guidelines](https://spectrum.adobe.com/web/rsp/components/tooltip#behaviors). (React Aria)
defaultOpenboolean-Whether the overlay is open by default (uncontrolled). (React Aria)
delaynumber600The delay time for the tooltip to show up. [See guidelines](https://spectrum.adobe.com/web/rsp/components/tooltip#behaviors). (React Aria)
isDisabledboolean-Whether the tooltip should be disabled, independent from the trigger. (React Aria)
isOpenboolean-Whether the overlay is open by default (controlled). (React Aria)
onOpenChange((isOpen: boolean) => void)-Handler that is called when the overlay's open state changes. (React Aria)
trigger"focus" | "hover"-By default, opens for both focus and hover. Can be made to open only for focus. (React Aria)

Accessibility

  • Shown on keyboard focus too, and read as the trigger's description.
  • Hover opens it after a delay; moving between tooltips is instant.

Keyboard

KeyDoes
TabFocusing the trigger shows it
EscapeHides it

Do and don't

Do

  • Keep it to a few words.

Don't

  • Don't put links or buttons in a tooltip.
  • Don't hide information people need: touch screens rarely show tooltips.
Tested with axe, keyboard and screen reader roles