Tooltip

View on Storybook

View source on GitHub

Import

import { Tooltip } from '@wordpress/components';

Props

NameTypeDefaultRequiredDescription
childrenReact.ReactElementYes

The anchor for the tooltip.

Note: Accepts only one child element.

classNamestring

Custom class name for the tooltip.

hideOnClickboolean

Option to hide the tooltip when the anchor is clicked.

@default true

delaynumber

The amount of time in milliseconds to wait before showing the tooltip.

@default 700

placementPlacement

Where the tooltip should be positioned relative to its parent.

@default top

shortcutShortcutProps[ 'shortcut' ]

An option for adding accessible keyboard shortcuts.

If shortcut is a string, it is expecting the display text. If shortcut is an object, it will accept the properties of display (string) and ariaLabel (string).

textstring

The text shown in the tooltip when anchor element is focused or hovered.

Examples

Default

const Default = ( props ) => (
	<Tooltip { ...props } />
);

Keyboard Shortcut

const KeyboardShortcut = ( props ) => (
	<Tooltip { ...props } />
);

Nested

In case one or more Tooltip components are rendered inside another Tooltip component, only the tooltip associated to the outermost Tooltip component will be rendered in the browser and shown to the user appropriately. The rest of the nested Tooltip components will simply no-op and pass-through their anchor.

const Nested = ( props ) => (
	<Tooltip { ...props } />
);