---
title: Tooltip 文字提示
order: 14
group:
  path: /components
nav:
  title: 组件
  path: /components
---

## 使用

### 使用原则

简单的文字提示气泡框。鼠标移入则显示提示，移出消失，气泡浮层不承载复杂文本和操作。
常用于提供一个按钮/文字/操作的文案解释。

> **设计师建议：** 展示内容不宜超过一行，若文字内容太多，单行宽度超过 320px 时，建议采用气泡卡片来展示。

### 基本使用

```jsx
import React from 'react';
import { Tooltip, Button } from 'quanta-design';

const text = <span>提示内容</span>;

const buttonWidth = 88;

const buttonStyle = { width: 88, marginRight: 8, marginBottom: 8 };

export default () => (
  <div className="demo">
    <div style={{ marginLeft: buttonWidth, whiteSpace: 'nowrap' }}>
      <Tooltip placement="topLeft" title={text}>
        <Button style={{ ...buttonStyle }}>TL</Button>
      </Tooltip>
      <Tooltip placement="top" title={text}>
        <Button style={{ ...buttonStyle }}>Top</Button>
      </Tooltip>
      <Tooltip placement="topRight" title={text}>
        <Button style={{ ...buttonStyle }}>TR</Button>
      </Tooltip>
    </div>
    <div style={{ width: buttonWidth, float: 'left' }}>
      <Tooltip placement="leftTop" title={text}>
        <Button style={{ ...buttonStyle }}>LT</Button>
      </Tooltip>
      <Tooltip placement="left" title={text}>
        <Button style={{ ...buttonStyle }}>Left</Button>
      </Tooltip>
      <Tooltip placement="leftBottom" title={text}>
        <Button style={{ ...buttonStyle }}>LB</Button>
      </Tooltip>
    </div>
    <div style={{ width: buttonWidth, marginLeft: buttonWidth * 4 + 16 }}>
      <Tooltip placement="rightTop" title={text}>
        <Button style={{ ...buttonStyle }}>RT</Button>
      </Tooltip>
      <Tooltip placement="right" title={text}>
        <Button style={{ ...buttonStyle }}>Right</Button>
      </Tooltip>
      <Tooltip placement="rightBottom" title={text}>
        <Button style={{ ...buttonStyle }}>RB</Button>
      </Tooltip>
    </div>
    <div
      style={{ marginLeft: buttonWidth, clear: 'both', whiteSpace: 'nowrap' }}
    >
      <Tooltip placement="bottomLeft" title={text}>
        <Button style={{ ...buttonStyle }}>BL</Button>
      </Tooltip>
      <Tooltip placement="bottom" title={text}>
        <Button style={{ ...buttonStyle }}>Bottom</Button>
      </Tooltip>
      <Tooltip placement="bottomRight" title={text}>
        <Button style={{ ...buttonStyle }}>BR</Button>
      </Tooltip>
    </div>
  </div>
);
```

## API

| 参数  | 说明     | 类型                               | 默认值 |
| ----- | -------- | ---------------------------------- | ------ |
| title | 提示文字 | string\|ReactNode\|() => ReactNode | 无     |

### 共同的 API

以下 API 为 Tooltip、Popconfirm、Popover 共享的 API。

| 参数               | 说明                                                                                                                                           | 类型                  | 默认值              |
| ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------------------- |
| arrowPointAtCenter | 箭头是否指向目标元素中心                                                                                                                       | boolean               | `false`             |
| autoAdjustOverflow | 气泡被遮挡时自动调整位置                                                                                                                       | boolean               | `true`              |
| defaultVisible     | 默认是否显隐                                                                                                                                   | boolean               | false               |
| getPopupContainer  | 浮层渲染父节点，默认渲染到 body 上                                                                                                             | Function(triggerNode) | () => document.body |
| mouseEnterDelay    | 鼠标移入后延时多少才显示 Tooltip，单位：秒                                                                                                     | number                | 0.1                 |
| mouseLeaveDelay    | 鼠标移出后延时多少才隐藏 Tooltip，单位：秒                                                                                                     | number                | 0.1                 |
| overlayClassName   | 卡片类名                                                                                                                                       | string                | 无                  |
| overlayStyle       | 卡片样式                                                                                                                                       | object                | 无                  |
| placement          | 气泡框位置，可选 `top` `left` `right` `bottom` `topLeft` `topRight` `bottomLeft` `bottomRight` `leftTop` `leftBottom` `rightTop` `rightBottom` | string                | top                 |
| trigger            | 触发行为，可选 `hover/focus/click/contextMenu`，可使用数组设置多个触发行为                                                                     | string \| string[]    | hover               |
| visible            | 用于手动控制浮层显隐                                                                                                                           | boolean               | false               |
| onVisibleChange    | 显示隐藏的回调                                                                                                                                 | (visible) => void     | 无                  |
| align              | 该值将合并到 placement 的配置中，设置参考 [rc-tooltip](https://github.com/react-component/tooltip)                                             | Object                | 无                  |

## 注意

请确保 `Tooltip` 的子元素能接受 `onMouseEnter`、`onMouseLeave`、`onFocus`、`onClick` 事件。
