feat: add fresh prop for tooltip (#45020)

* chore: init

* docs: add fresh

* docs: add faq

* docs: update
This commit is contained in:
二货爱吃白萝卜 2023-09-22 15:45:22 +08:00 committed by GitHub
parent 05878dd300
commit 3e325f4eed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 1 deletions

View File

@ -49,6 +49,7 @@ The following APIs are shared by Tooltip, Popconfirm, Popover.
| color | The background color | string | - | 4.3.0 |
| defaultOpen | Whether the floating tooltip card is open by default | boolean | false | 4.23.0 |
| destroyTooltipOnHide | Whether destroy tooltip when hidden | boolean | false | |
| fresh | Tooltip will cache content when it is closed by default. Setting this property will always keep updating | boolean | false | 5.10.0 |
| getPopupContainer | The DOM container of the tip, the default behavior is to create a `div` element in `body` | (triggerNode: HTMLElement) => HTMLElement | () => document.body | |
| mouseEnterDelay | Delay in seconds, before tooltip is shown on mouse enter | number | 0.1 | |
| mouseLeaveDelay | Delay in seconds, before tooltip is hidden on mouse leave | number | 0.1 | |
@ -78,3 +79,26 @@ It will follow `placement` config when screen has enough space. And flip when sp
<img alt="shift" height="200" src="https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*sxaTTJjLtIMAAAAAAAAAAAAADrJ8AQ/original" />
When `placement` is set to edge align such as `topLeft` `bottomRight`, it will only do flip but not do shift.
### Why Tooltip not update content when close?
Tooltip will cache content when it is closed to avoid flicker when content is updated:
```jsx
// `title` will not blink when `user` is empty
<Tooltip open={user} title={user?.name} />
```
<div>
<img alt="no blink" height="50" src="https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*KVx7QLOYwVsAAAAAAAAAAAAADrJ8AQ/original" />
</div>
If need update content when close, you can set `fresh` property ([#44830](https://github.com/ant-design/ant-design/issues/44830)):
```jsx
<Tooltip open={user} title={user?.name} fresh />
```
<div>
<img alt="no blink" height="50" src="https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*rUbsR4xWpMsAAAAAAAAAAAAADrJ8AQ/original" />
</div>

View File

@ -51,6 +51,7 @@ demo:
| color | 背景颜色 | string | - | 4.3.0 |
| defaultOpen | 默认是否显隐 | boolean | false | 4.23.0 |
| destroyTooltipOnHide | 关闭后是否销毁 Tooltip | boolean | false | |
| fresh | 默认情况下Tooltip 在关闭时会缓存内容。设置该属性后会始终保持更新 | boolean | false | 5.10.0 |
| getPopupContainer | 浮层渲染父节点,默认渲染到 body 上 | (triggerNode: HTMLElement) => HTMLElement | () => document.body | |
| mouseEnterDelay | 鼠标移入后延时多少才显示 Tooltip单位秒 | number | 0.1 | |
| mouseLeaveDelay | 鼠标移出后延时多少才隐藏 Tooltip单位秒 | number | 0.1 | |
@ -80,3 +81,26 @@ demo:
<img alt="shift" height="200" src="https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*sxaTTJjLtIMAAAAAAAAAAAAADrJ8AQ/original" />
当设置为边缘对齐方向如 `topLeft` `bottomRight` 等,则会仅做翻转而不做位移。
### 为何 Tooltip 的内容在关闭时不会更新?
Tooltip 默认在关闭时会缓存内容,以防止内容更新时出现闪烁:
```jsx
// `title` 不会因为 `user` 置空而闪烁置空
<Tooltip open={user} title={user?.name} />
```
<div>
<img alt="no blink" height="50" src="https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*KVx7QLOYwVsAAAAAAAAAAAAADrJ8AQ/original" />
</div>
如果需要在关闭时也更新内容,可以设置 `fresh` 属性(例如 [#44830](https://github.com/ant-design/ant-design/issues/44830) 中的场景):
```jsx
<Tooltip open={user} title={user?.name} fresh />
```
<div>
<img alt="no blink" height="50" src="https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*rUbsR4xWpMsAAAAAAAAAAAAADrJ8AQ/original" />
</div>

View File

@ -150,7 +150,7 @@
"rc-table": "~7.34.0",
"rc-tabs": "~12.12.1",
"rc-textarea": "~1.4.0",
"rc-tooltip": "~6.0.1",
"rc-tooltip": "~6.1.0",
"rc-tree": "~5.7.12",
"rc-tree-select": "~5.13.0",
"rc-upload": "~4.3.4",