Skip to content

feat(Tabs): support showSearch in more dropdown#992

Open
EmilyyyLiu wants to merge 7 commits into
react-component:masterfrom
EmilyyyLiu:feat/add-showSearch
Open

feat(Tabs): support showSearch in more dropdown#992
EmilyyyLiu wants to merge 7 commits into
react-component:masterfrom
EmilyyyLiu:feat/add-showSearch

Conversation

@EmilyyyLiu

@EmilyyyLiu EmilyyyLiu commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

概述

为 Tabs 组件的更多下拉菜单添加 popupRender 属性,支持自定义弹出内容。

相关 Issue

ant-design/ant-design#30719

改动内容

  • src/interface.ts: 新增 PopupRender 类型定义和 popupRender 属性到 MoreProps
  • src/index.ts: 导出 PopupRender 类型
  • src/TabNavList/OperationNode.tsx: 实现 popupRender 功能,允许用户自定义下拉菜单内容
  • README.md: 更新 API 文档
  • tests/overflow.test.tsx: 添加测试用例

使用方法

<Tabs
  more={{
    popupRender: (menu, { tabs, onClose }) => (
      <div>
        <div>共有 {tabs.length} 个标签</div>
        {menu}
      </div>
    ),
  }}
  items={items}
/>

@vercel

vercel Bot commented Jun 26, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the React Component Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

新增 more.showSearch 配置及其类型说明,OperationNode 支持更多下拉内搜索、过滤、键盘导航和受控搜索值,并同步更新样式、示例文档与测试。

Changes

搜索下拉支持

Layer / File(s) Summary
API 契约
src/interface.ts, README.md
新增 ShowSearchConfigMoreProps.showSearch,并在 README 中补充 moreMoreProps 的配置说明。
搜索过滤与交互
src/TabNavList/OperationNode.tsx
OperationNode 解析搜索配置,生成 filteredTabs,并将菜单渲染、键盘导航、输入交互和 overlay 结构切换到搜索模式。
下拉样式
assets/dropdown.less
下拉面板补充隐藏态、搜索容器、顶部搜索栏和菜单滚动布局。
示例与测试
docs/demo/search-dropdown.md, docs/examples/search-dropdown.tsx, tests/overflow.test.tsx
新增 search-dropdown 演示页与示例组件,并补充输入框渲染、占位符、输入更新、onSearch 调用和搜索值清空的测试。

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • react-component/tabs#812:同样触及 src/TabNavList/OperationNode.tsx 的键盘处理路径,与本次搜索下拉的键盘交互修改位于相近代码点。

Suggested reviewers

  • zombieJ

Poem

我是一只小兔,蹦进 more 的门,
鼻尖闻到搜索框,词儿一输就分门。
方向键轻轻跳,菜单排排站稳,
Tabs 眨眨眼:哎呀,找到了那一份。

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed 标题准确概括了为 Tabs 的 more 下拉新增 showSearch 支持这一主要变更。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ 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.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces a search feature within the tabs overflow dropdown, allowing users to filter tabs. It includes documentation, styling, a demo, and unit tests. The review feedback highlights three key areas for improvement: first, safely extracting text from tab.label since it can be a React node rather than a plain string; second, resetting the selected key when the active tab is filtered out to prevent selecting hidden tabs; and third, enhancing accessibility by auto-focusing the search input upon opening and supporting the Escape key to close the dropdown.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/TabNavList/OperationNode.tsx Outdated
Comment thread src/TabNavList/OperationNode.tsx Outdated
Comment thread src/TabNavList/OperationNode.tsx Outdated
@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.98%. Comparing base (2a1774b) to head (bbd079e).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #992   +/-   ##
=======================================
  Coverage   98.98%   98.98%           
=======================================
  Files          18       18           
  Lines         788      792    +4     
  Branches      228      238   +10     
=======================================
+ Hits          780      784    +4     
  Misses          8        8           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (1)
tests/overflow.test.tsx (1)

675-746: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

建议把回归测试补到关闭清空和键盘导航。

Line 675-746 目前只覆盖了输入渲染、筛选和 onSearch。这次改动里更容易回归的是默认 autoClearSearchValue=true 的关闭清空,以及 ArrowUp/ArrowDown/Enter 的键盘选择流程,建议顺手补上这两类断言。

🤖 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 `@tests/overflow.test.tsx` around lines 675 - 746, Current tests in
overflow.test.tsx only cover rendering, filtering, and onSearch in the search
dropdown; add regression coverage for the default autoClearSearchValue=true
behavior and the keyboard navigation/selection flow. Extend the existing
overflow dropdown tests around getTabs, showSearch, and the rc-tabs-dropdown
input to assert that the search value clears appropriately after selection when
autoClearSearchValue is enabled. Also add key event coverage for ArrowUp,
ArrowDown, and Enter to verify the dropdown item focus and selection path does
not regress.
🤖 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 `@docs/examples/search-dropdown.tsx`:
- Around line 53-56: Search-dropdown 示例里的 Tabs 被固定为 activeKey="1" 且 onChange
被忽略,导致点击搜索结果切换标签无效;请在 search-dropdown.tsx 中为 Tabs 单独维护一个 activeKey 状态,并在
onChange 里更新它,让受控的 searchValue 与 tab 切换状态分离,保持示例可正常切换。

In `@README.md`:
- Around line 121-132: The new `more` / `MoreProps` API table entries in the
README are written in Chinese while the rest of the document is English; update
these descriptions to English to keep the public documentation language
consistent. Please revise the `MoreProps` section and its nested fields (`icon`,
`showSearch`, `placeholder`, `searchValue`, `onSearch`, `autoClearSearchValue`)
so the wording matches the surrounding README style.

In `@src/TabNavList/OperationNode.tsx`:
- Around line 145-147: `OperationNode` needs to keep `selectedKey` in sync with
the current `filteredTabs` result set. Update the selection logic around
`enabledTabs`, the Enter handler, and the `open`/`filteredTabs` effect so
`selectedKey` is always coerced to a valid key in the visible tabs (prefer
current `activeKey`, otherwise the first enabled tab, otherwise `null`). Also
fix the `findIndex(...) || 0` fallback in `OperationNode` so a missing match
does not preserve an invalid index, preventing keyboard confirm and highlight
from pointing at hidden tabs.
- Around line 80-82: The search filtering in OperationNode should not rely on
String(tab.label), because ReactNode labels can stringify to “[object Object]”
and fail in the “more” search. Update the filtering logic around filteredTabs to
use visible text derived from the tab label, or add a configurable filter text
source, so tabs with element labels still match correctly. Keep the fix
localized to the tab filtering path and preserve the existing Tabs API behavior.

---

Nitpick comments:
In `@tests/overflow.test.tsx`:
- Around line 675-746: Current tests in overflow.test.tsx only cover rendering,
filtering, and onSearch in the search dropdown; add regression coverage for the
default autoClearSearchValue=true behavior and the keyboard navigation/selection
flow. Extend the existing overflow dropdown tests around getTabs, showSearch,
and the rc-tabs-dropdown input to assert that the search value clears
appropriately after selection when autoClearSearchValue is enabled. Also add key
event coverage for ArrowUp, ArrowDown, and Enter to verify the dropdown item
focus and selection path does not regress.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: edab3f81-7197-4ef8-9dd1-712eb57eb981

📥 Commits

Reviewing files that changed from the base of the PR and between 926f67e and f22edac.

📒 Files selected for processing (7)
  • README.md
  • assets/dropdown.less
  • docs/demo/search-dropdown.md
  • docs/examples/search-dropdown.tsx
  • src/TabNavList/OperationNode.tsx
  • src/interface.ts
  • tests/overflow.test.tsx

Comment thread docs/examples/search-dropdown.tsx Outdated
Comment thread README.md Outdated
Comment thread src/TabNavList/OperationNode.tsx Outdated
Comment thread src/TabNavList/OperationNode.tsx Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/overflow.test.tsx (1)

676-740: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

请把 fake timers 的恢复放进 try/finally 或统一的 teardown。

现在只有走到测试末尾才会执行 jest.useRealTimers();中间任一断言失败都会把 fake timers 泄漏到后续用例,造成串扰和偶发失败。

可参考的改法
   it('should have input and support keyboard navigation', () => {
-    jest.useFakeTimers();
-    const onChange = jest.fn();
-    const { container } = render(
-      getTabs({
-        onChange,
-        ...
-      }),
-    );
-
-    ...
-
-    jest.useRealTimers();
+    jest.useFakeTimers();
+    try {
+      const onChange = jest.fn();
+      const { container } = render(
+        getTabs({
+          onChange,
+          ...
+        }),
+      );
+
+      ...
+    } finally {
+      jest.useRealTimers();
+    }
   });

Also applies to: 744-781

🤖 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 `@tests/overflow.test.tsx` around lines 676 - 740, Wrap the fake-timer setup in
this test around the existing overflow dropdown flow with a try/finally (or move
cleanup into a shared teardown) so `jest.useRealTimers()` always runs even if an
assertion fails. Use the current test block in `tests/overflow.test.tsx` that
calls `jest.useFakeTimers()`, `triggerResize`, and `fireEvent` interactions, and
ensure the cleanup is tied to the test’s execution rather than the final line
only to prevent timer leakage into later cases.
🧹 Nitpick comments (1)
tests/overflow.test.tsx (1)

675-742: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

建议补一条“关闭下拉后清空搜索值”的用例。

这次改动的核心行为之一就是关闭时重置搜索值,而当前新增用例还没有锁住这个默认契约;后续如果回归,现有测试捕不到。至少补一条关闭后再打开应为空的断言,最好再覆盖 autoClearSearchValue: false

Also applies to: 743-781

🤖 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 `@tests/overflow.test.tsx` around lines 675 - 742,
现有新增用例只覆盖了搜索和键盘选择,没有验证关闭下拉后搜索值会被重置这一关键行为。请在相关测试中围绕 getTabs、showSearch
和下拉触发流程补充断言:关闭 Dropdown 后再次打开时 input 应为空,并最好再补一个 autoClearSearchValue 为 false
时不会清空的分支,确保默认契约被锁定。
🤖 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.

Outside diff comments:
In `@tests/overflow.test.tsx`:
- Around line 676-740: Wrap the fake-timer setup in this test around the
existing overflow dropdown flow with a try/finally (or move cleanup into a
shared teardown) so `jest.useRealTimers()` always runs even if an assertion
fails. Use the current test block in `tests/overflow.test.tsx` that calls
`jest.useFakeTimers()`, `triggerResize`, and `fireEvent` interactions, and
ensure the cleanup is tied to the test’s execution rather than the final line
only to prevent timer leakage into later cases.

---

Nitpick comments:
In `@tests/overflow.test.tsx`:
- Around line 675-742: 现有新增用例只覆盖了搜索和键盘选择,没有验证关闭下拉后搜索值会被重置这一关键行为。请在相关测试中围绕
getTabs、showSearch 和下拉触发流程补充断言:关闭 Dropdown 后再次打开时 input 应为空,并最好再补一个
autoClearSearchValue 为 false 时不会清空的分支,确保默认契约被锁定。

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1c3ccb13-0aec-4d33-9020-79badd0aa09f

📥 Commits

Reviewing files that changed from the base of the PR and between 186feeb and da9a598.

📒 Files selected for processing (1)
  • tests/overflow.test.tsx

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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 `@tests/overflow.test.tsx`:
- Around line 740-751: The “close and reopen” test is using Escape on the search
input, but OperationNode’s input onKeyDown does not handle that path; the real
close action is on the .rc-tabs-nav-more trigger. Update the
autoClearSearchValue: false test to close the dropdown by interacting with the
more button in TabNavList/OperationNode, then reopen it and assert the input
still contains the search value. Use the existing OperationNode dropdown and
input selectors so the test covers the actual close/reopen flow instead of
reusing the same open input.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f7df2792-f8ec-4b79-bd5f-ec560fa11c20

📥 Commits

Reviewing files that changed from the base of the PR and between da9a598 and 20934ca.

📒 Files selected for processing (1)
  • tests/overflow.test.tsx

Comment thread tests/overflow.test.tsx Outdated
Comment thread tests/overflow.test.tsx Fixed
Comment thread src/TabNavList/OperationNode.tsx Outdated
- Add PopupRender type with tabs, activeKey, and onClose
- Implement popupRender in OperationNode
- Add demo example for search in overflow menu

Co-Authored-By: Claude <noreply@anthropic.com>
@EmilyyyLiu EmilyyyLiu force-pushed the feat/add-showSearch branch from 755768b to 02f91bb Compare July 3, 2026 02:55
刘欢 and others added 4 commits July 3, 2026 11:18
- Add popupRender unit tests
- Add documentation in README
- Remove demo files (will be implemented in ant-design)

Co-Authored-By: Claude <noreply@anthropic.com>
Comment thread tests/overflow.test.tsx Fixed
@zombieJ

zombieJ commented Jul 3, 2026

Copy link
Copy Markdown
Member

来自 Code Review Skill

这个 PR 在做什么

这个 PR 给 Tabs 的 overflow more 下拉增加 popupRender,允许调用方包一层自定义弹层内容,并通过 info.tabsinfo.onClose 拿到隐藏 tab 列表与关闭能力。实现集中在 OperationNode,同时导出 PopupRender 类型并补了一条单测和 README API 文档。

结论

有条件合并

实现本身没有看到会直接破坏现有 Tabs 行为的阻塞问题;主流程 CI 通过。合并前建议确认 Vercel 失败状态不是必需检查,并修一下新增测试的无效关闭断言。

问题清单

🔴 高优先级(阻塞合并)

🟡 中优先级(建议修复)

  • onClose 的测试断言没有真正验证下拉关闭tests/overflow.test.tsx:700
    新增用例调用了 onClose(),但最后用 container.querySelector('.rc-tabs-dropdown') 断言;dropdown popup 实际是通过 document/portal 查询,container 里本来就查不到 popup,所以即使 onClose 失效这条测试也可能通过。建议改成用 document.querySelector('.rc-tabs-dropdown-hidden')、或确认 popup 消失/隐藏,并最好在调用 onClose 前先断言 popup 已打开。

🟢 低优先级(可选改进)

  • 文档把 more 的既有 Dropdown 配置简化掉了README.md:78
    这里从 MoreProps 改成了只列 iconpopupRender 的 inline 类型,会让读者误以为 trigger 等原有 DropdownProps 不再支持。建议保留 MoreProps,并单独补一小段 popupRender 说明。

  • 中文 README 未同步新增 APIREADME.zh-CN.md:78
    仓库同时维护英文和中文 README,这次只更新了英文侧。建议同步补充 popupRender,避免双语文档不一致。

@EmilyyyLiu EmilyyyLiu force-pushed the feat/add-showSearch branch from 821d59d to bbd079e Compare July 3, 2026 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants