Skip to content

feat(actions): support customizing the tooltip of each action item - #2004

Open
Y-MuYi wants to merge 2 commits into
ant-design:mainfrom
Y-MuYi:feat-1952-actions-tooltip
Open

feat(actions): support customizing the tooltip of each action item#2004
Y-MuYi wants to merge 2 commits into
ant-design:mainfrom
Y-MuYi:feat-1952-actions-tooltip

Conversation

@Y-MuYi

@Y-MuYi Y-MuYi commented Aug 3, 2026

Copy link
Copy Markdown

Closes #1952

关联原始 issue:#1834

背景

Actions 操作项的 Tooltip 当前固定为 title={label},无法自定义文案,也无法关闭(例如在 z-index 很高的容器里 tooltip 可能被遮住、或场景上根本不需要提示)。

改动

为每个操作项新增 `tooltip` 配置:

```ts
tooltip?: string | TooltipProps | false
```

取值 行为
`undefined` 保持默认 `title={label}`
`string` 以该字符串作为 tooltip `title`
`TooltipProps` 对象 合并到默认 `title={label}` 之上(可自定义 `placement`、`color`、`getPopupContainer` 等)
`false` 不渲染 Tooltip
  • `interface.ts`:在 `ItemType` 上新增 `tooltip`(沿用 sender 组件 `import type { TooltipProps } from 'antd'` 的写法)。
  • `Item.tsx` `items=[...]` 渲染路径 与 `ActionsItem.tsx` 独立 `Actions.Item` 组件 均支持,复用同一套解析逻辑。
  • 新增 `demo/custom-tooltip.tsx`,演示自定义字符串 / `false` 关闭 / `TooltipProps` 对象(`placement`、`color`)/ 默认 label。
  • 中英文档注册 demo,并更新 `ItemType`、`Actions.Item` 两处 API 表。
  • 新增单测覆盖以上四类取值(独立组件与 items 路径各一套)。

验证

  • biome 格式检查通过。
  • `tsc --noEmit` 对改动文件无新增类型错误。

备注:本地 `jest` 因 `.jest` setup 中 `antd@6` 的 `genStyleUtils is not a function` 报错而无法运行(仓库级环境问题,既有用例同样失败,非本次改动引入),依赖 CI 验证单测。

Summary by CodeRabbit

  • 新功能

    • Actions 项目新增可配置的 Tooltip。
    • 支持使用自定义文本、完整 Tooltip 配置,或设置为 false 禁用提示。
    • 未特别配置时,默认使用项目标签作为提示标题。
    • 移动端自动直接展示内容,避免显示 Tooltip。
  • 文档

    • 新增自定义 Tooltip 示例及相关 API 配置说明。

Add `tooltip?: string | TooltipProps | false` to each action item so the
Tooltip can be customized or disabled (`false` skips rendering the Tooltip
entirely). Defaults to the existing `title={label}` behavior. Applied to both
the `items` render path (Item.tsx) and the standalone `Actions.Item` component
(ActionsItem.tsx).

Closes ant-design#1952
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@dosubot dosubot Bot added the enhancement New feature or request label Aug 3, 2026
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Actions 的每个操作项新增 tooltip 配置。该配置支持字符串、TooltipPropsfalse。默认标题使用 label。移动端和禁用状态不渲染 Tooltip。测试、示例及中英文文档同步更新。

Changes

Actions Tooltip 功能

Layer / File(s) Summary
Tooltip 契约与渲染逻辑
packages/x/components/actions/interface.ts, packages/x/components/actions/ActionsItem.tsx, packages/x/components/actions/Item.tsx
新增 tooltip?: string | TooltipProps | false。组件支持默认标题、自定义标题、属性合并和禁用 Tooltip。
Tooltip 行为测试
packages/x/components/actions/__tests__/action-item.test.tsx, packages/x/components/actions/__tests__/index.test.tsx
新增默认标签、自定义文本、禁用状态和 TooltipProps 回退行为测试。
示例与 API 文档
packages/x/components/actions/demo/custom-tooltip.tsx, packages/x/components/actions/index.en-US.md, packages/x/components/actions/index.zh-CN.md
新增自定义 Tooltip 示例,并更新中英文 API 说明。

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant 操作项
  participant Tooltip配置解析
  participant Tooltip
  操作项->>Tooltip配置解析: 传入 tooltip
  Tooltip配置解析->>Tooltip配置解析: 默认使用 label
  Tooltip配置解析->>Tooltip: 非移动端且未禁用时传入配置
  Tooltip-->>操作项: 显示提示内容
Loading

Possibly related PRs

  • ant-design/x#1973:涉及相同组件、类型、测试、示例和文档的 Actions Tooltip 配置。
  • ant-design/x#1977:涉及相同的逐项 tooltip 配置实现。

Suggested labels: documentation, javascript

Suggested reviewers: kimteayon

Poem

兔子敲代码,Tooltip 排成行
默认跟随 label,文本可更改
false 让提示安静退场
测试验证每一步
耳朵一抖,文档也更新啦 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题明确概括了为每个 Actions 操作项提供 Tooltip 自定义能力的主要变更。
Linked Issues check ✅ Passed PR 实现了 #1952 要求的 tooltip 类型、禁用逻辑、演示、单测及中英文档更新。
Out of Scope Changes check ✅ Passed 所有代码、测试、演示和文档变更均服务于 #1952 的 Tooltip 自定义目标,未发现无关改动。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Warning

⚠️ This pull request shows signs of AI-generated slop (redundant_comments, trivial_assertion). It has been flagged by CodeRabbit slop detection and should be reviewed carefully.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/x/components/actions/__tests__/action-item.test.tsx`:
- Around line 33-37: Update the tests at
packages/x/components/actions/__tests__/action-item.test.tsx:33-37 and
packages/x/components/actions/__tests__/index.test.tsx:111-116 to trigger each
rendered icon and assert that no Tooltip overlay containing the label appears
when tooltip={false}, using fake timers or the existing Tooltip mock as
appropriate.
- Around line 17-30: Update the tooltip-opening calls in the ActionsItem tests
to pass the element returned by screen.getByText('icon') directly, rather than
its parentElement. Apply this to all three positive tooltip tests, including the
additional case around the third occurrence, so hover events reach the Tooltip
trigger node.

In `@packages/x/components/actions/index.en-US.md`:
- Line 49: Update the Version column for the tooltip property in ItemType and
Actions.Item across packages/x/components/actions/index.en-US.md lines 49 and
83, and packages/x/components/actions/index.zh-CN.md lines 50 and 84, replacing
“-” with the actual version in which this public API was first released. Keep
all other documentation unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 36ff8c15-9fd2-4d40-b6c5-c006f9679cfc

📥 Commits

Reviewing files that changed from the base of the PR and between b529d8e and 88a5db3.

📒 Files selected for processing (8)
  • packages/x/components/actions/ActionsItem.tsx
  • packages/x/components/actions/Item.tsx
  • packages/x/components/actions/__tests__/action-item.test.tsx
  • packages/x/components/actions/__tests__/index.test.tsx
  • packages/x/components/actions/demo/custom-tooltip.tsx
  • packages/x/components/actions/index.en-US.md
  • packages/x/components/actions/index.zh-CN.md
  • packages/x/components/actions/interface.ts

Comment on lines +17 to +30
it('renders tooltip with label by default', async () => {
render(<ActionsItem defaultIcon="icon" label="Default Label" />);
openTooltip(screen.getByText('icon').parentElement!);
await waitFor(() => {
expect(screen.getByText('Default Label')).toBeInTheDocument();
});
});

it('uses a custom string as the tooltip title', async () => {
render(<ActionsItem defaultIcon="icon" label="Label" tooltip="Custom Tooltip" />);
openTooltip(screen.getByText('icon').parentElement!);
await waitFor(() => {
expect(screen.getByText('Custom Tooltip')).toBeInTheDocument();
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

向 Tooltip 触发节点发送 hover 事件。

screen.getByText('icon') 已经是 <Tooltip> 的子节点。parentElement 是测试容器,不会触发 Tooltip 的事件处理器。因此这些正向测试会在可执行 Jest 后失败,或无法验证 Tooltip 行为。

建议修改
-    openTooltip(screen.getByText('icon').parentElement!);
+    openTooltip(screen.getByText('icon'));

对第 19、27、41 行分别应用此修改。

Also applies to: 39-45

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/x/components/actions/__tests__/action-item.test.tsx` around lines 17
- 30, Update the tooltip-opening calls in the ActionsItem tests to pass the
element returned by screen.getByText('icon') directly, rather than its
parentElement. Apply this to all three positive tooltip tests, including the
additional case around the third occurrence, so hover events reach the Tooltip
trigger node.

Comment on lines +33 to +37
it('renders no tooltip when tooltip is false', () => {
const { container } = render(<ActionsItem defaultIcon="icon" label="Label" tooltip={false} />);
// icon renders without a Tooltip wrapper
expect(container.textContent).toContain('icon');
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

验证 tooltip={false} 实际禁用 Tooltip。

这两项测试只验证图标仍然存在。即使组件仍渲染 <Tooltip>,该断言也会通过。触发图标后,使用 fake timers 或 Tooltip mock 断言不会出现 label 对应的浮层。

  • packages/x/components/actions/__tests__/action-item.test.tsx#L33-L37: 触发 standalone ActionsItem,并断言 Tooltip 浮层不出现。
  • packages/x/components/actions/__tests__/index.test.tsx#L111-L116: 触发 items 渲染路径中的图标,并断言 Tooltip 浮层不出现。
📍 Affects 2 files
  • packages/x/components/actions/__tests__/action-item.test.tsx#L33-L37 (this comment)
  • packages/x/components/actions/__tests__/index.test.tsx#L111-L116
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/x/components/actions/__tests__/action-item.test.tsx` around lines 33
- 37, Update the tests at
packages/x/components/actions/__tests__/action-item.test.tsx:33-37 and
packages/x/components/actions/__tests__/index.test.tsx:111-116 to trigger each
rendered icon and assert that no Tooltip overlay containing the label appears
when tooltip={false}, using fake timers or the existing Tooltip mock as
appropriate.

| --- | --- | --- | --- | --- |
| key | Unique identifier for custom action | string | - | - |
| label | Display label for custom action | string | - | - |
| tooltip | Tooltip of the action item, set to `false` to disable the Tooltip | string \| TooltipProps \| false | label | - |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: 查找包版本信息,确定新特性应标注的版本号。
fd package.json --exec grep -n '"version"' {} \; -path '*/x/*'

Repository: ant-design/x

Length of output: 342


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== candidate package manifests =="
find . -path '*/x/*' -maxdepth 4 -name package.json -print | sort

echo
echo "== version declarations in x manifests =="
find . -path '*/x/*' -maxdepth 4 -name package.json -print | sort | while read -r f; do
  echo "--- ${f#$PWD/}"
  node -e 'const fs=require("fs"); const p=process.argv[1]; const j=JSON.parse(fs.readFileSync(p,"utf8")); if(j.packages && Object.keys(j.packages).length) { fs.writeFileSync(process.stdout.fd+1, JSON.stringify(j.packages,null,2)) } else { delete j.dependencies; delete j.devDependencies; delete j.scripts; console.log(JSON.stringify({path:p, version:j.version},null,2))}' "$f"
done

echo
echo "== actions docs tooltip entries =="
for f in packages/x/components/actions/index.en-US.md packages/x/components/actions/index.zh-CN.md; do
  echo "--- $f"
  grep -nE '^(#\s*|\|[^|]*tooltip[^|]*\|)' "$f" || true
done

echo
echo "== nearby doc Version entries for comparison =="
sed -n '35,90p' packages/x/components/actions/index.en-US.md
sed -n '35,90p' packages/x/components/actions/index.zh-CN.md

echo
echo "== x package files =="
git ls-files | rg '(^|/)x/(packages/|component|package\.json$|README)' | head -80

Repository: ant-design/x

Length of output: 10898


为新增的 tooltip 属性填写正确的版本号。

tooltip 是新增公开 API,当前英文版和中文版的 ItemType.tooltip / Actions.Item.tooltip 文档都未填写 Version。请将两处英文文档与对应中文文档中该属性的 Version 列从 - 改为该属性首次发布对应的实际版本号。

📍 Affects 2 files
  • packages/x/components/actions/index.en-US.md#L49-L49 (this comment)
  • packages/x/components/actions/index.en-US.md#L83-L83
  • packages/x/components/actions/index.zh-CN.md#L50-L50
  • packages/x/components/actions/index.zh-CN.md#L84-L84
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/x/components/actions/index.en-US.md` at line 49, Update the Version
column for the tooltip property in ItemType and Actions.Item across
packages/x/components/actions/index.en-US.md lines 49 and 83, and
packages/x/components/actions/index.zh-CN.md lines 50 and 84, replacing “-” with
the actual version in which this public API was first released. Keep all other
documentation unchanged.

@Y-MuYi

Y-MuYi commented Aug 4, 2026

Copy link
Copy Markdown
Author

#1952

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Good First Issue] Actions 支持自定义每个操作项的 Tooltip

1 participant