Web and native

Tooltip in kanso-ui 0.59.0, for React.

import { Tooltip } from '@kanso-labs/kanso-ui'

A short text label for the element it wraps, shown while that element is hovered or focused.

It is Material Design's plain tooltip: a 24dp container on inverse surface with 8dp of padding, holding body small text in inverse on surface, at the smallest corner the library has and with no elevation. A long label wraps at 320px wide. The rich tooltip on the same page, with a subhead and buttons, is a Popover.

What you provide

  • children: the one element the tooltip describes. It must be able to take focus; wrap anything that cannot in Focusable, which the package re-exports.
  • label: what the tooltip says, as text.

Props

PropTypeDefaultDescription
alignOverlayAlign'center'Where the tooltip sits along the side it opens on.
alignOffsetnumber—Shifts the tooltip along that side, in pixels.
childrenReactNode—The element the tooltip describes, and nothing else. It has to be able to take focus, since a tooltip a keyboard cannot reach is one most people never see — wrap anything that cannot in `Focusable`, which this package re-exports.
classNameClassNameOrFunction<TooltipRenderProps>—A function may compute the class from the tooltip's render state.
containerElement—Where to portal the tooltip. Defaults to the container of the `ThemeScope` around it, which keeps the tooltip on that scope's tokens, or to the end of `<body>` where there is none. A subtree themed through the `themeScope` class has no container of its own, so point this inside it, or the tooltip renders outside and keeps the page's tokens.
label requiredReactNode—What the tooltip says: one to three words, in sentence case.
purpose'hint' | 'name''name'What the label is to the control. `name` is Kanso's tooltip on an icon-only control: the label shows the control's name, which its `aria-label` gives, and the control carries no description, so a screen reader reads the word once. `hint` describes the control instead, for a shortcut or a word its name does not hold, and leaves its name to the control. Never both: a label that is the name and the description is read twice.
sideOverlaySide'bottom'Which side of the element the tooltip opens on. It flips to the opposite side on its own when there is no room. `start` and `end` follow the writing direction, so `end` is the right in English and the left in Arabic; `left` and `right` stay put in either.
sideOffsetnumber4The gap between the element and the tooltip, in pixels.
styleStyleOrFunction<TooltipRenderProps>—A function may compute the style from the tooltip's render state.

Also takes the props of Omit<TooltipTriggerComponentProps, 'children'>.

Example

import { IconButton, Tooltip } from '@kanso-labs/kanso-ui'

<Tooltip label="Search">
  <IconButton aria-label="Search">
    <SearchIcon />
  </IconButton>
</Tooltip>

The design’s classes

k-tooltip for the bubble. The anchor, the position and showing and hiding (k-tip, is-open, is-dismissed) are written in the preview until bundle.css has them.

Maps to Tooltip in kanso-ui and react-native-kanso-ui.