Tooltip 是一个 React 组件,用于在节点获得焦点或被鼠标悬停时渲染浮动帮助文本。如果工具提示超出页面边界,其位置会自动翻转。
import { Tooltip } from '@wordpress/components';
const MyTooltip = () => (
<Tooltip text="More information">
<div>Hover for more information</div>
</Tooltip>
);Tooltip is a React component to render floating help text relative to a node when it receives focus or it is hovered upon by a mouse. If the tooltip exceeds the bounds of the page in the direction it opens, its position will be flipped automatically.
Render a Tooltip, passing as a child the element to which it should anchor:
import { Tooltip } from '@wordpress/components';
const MyTooltip = () => (
<Tooltip text="More information">
<div>Hover for more information</div>
</Tooltip>
);
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.
The component accepts the following props:
children: React.ReactElementThe element to which the tooltip should anchor.
NOTE: Accepts only one child element.
delay: numberThe amount of time in milliseconds to wait before showing the tooltip.
700hideOnClick: booleanOption to hide the tooltip when the anchor is clicked.
trueplacement: 'top' | 'top-start' | 'top-end' | 'right' | 'right-start' | 'right-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'left' | 'left-start' | 'left-end'Used to specify the tooltip’s placement with respect to its anchor.
'top'position: stringNote: use the placement prop instead when possible.
Legacy way to specify the popover’s position with respect to its anchor. Specify y- and x-axis as a space-separated string. Supports 'top', 'middle', 'bottom' y axis, and 'left', 'center', 'right' x axis.
'top'shortcut: string | objectAn 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.
text: stringThe text shown in the tooltip when anchor element is focused or hovered.