Skip to content

feat: Merge searchValue,autoClearSearchValue and onSearch into the showSearch field #593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 13, 2025

Conversation

EmilyyyLiu
Copy link
Contributor

@EmilyyyLiu EmilyyyLiu commented May 14, 2025

ant-design/ant-design#33482

Summary by CodeRabbit

  • 新功能
    • 级联选择器的搜索配置现支持通过 showSearch 对象集中设置搜索值、搜索回调及自动清除搜索值功能,且默认自动清除搜索值为开启状态。
  • 测试
    • 新增用例,验证通过 showSearch 配置搜索值、回调及自动清除搜索值行为的正确性,包括搜索结果展示和选中后搜索值保留。
  • 文档
    • 顶层 searchValueonSearchautoClearSearchValue 属性已标记为弃用,建议改用 showSearch 对象中的对应配置。
    • 重构并扩展了 showSearch 相关属性的文档说明,新增详细子属性说明,明确 autoClearSearchValue 仅在可勾选时生效。

Copy link

vercel bot commented May 14, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
cascader ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 13, 2025 8:28am

Copy link

coderabbitai bot commented May 14, 2025

## Walkthrough

本次变更将搜索相关的状态和回调集中到 `showSearch` 配置对象中。新增了 `searchValue``onSearch``autoClearSearchValue` 可选属性到 `ShowSearchType`(现重命名为 `SearchConfig`)接口,并在组件内部优先使用 `showSearch` 内的配置。原有的顶层 `searchValue``onSearch``autoClearSearchValue` 属性已标记为废弃,保留兼容。测试用例新增了对新用法的验证,文档重构了 `showSearch` 相关说明。

## Changes

| 文件/路径                      | 变更摘要                                                                                      |
|-------------------------------|-----------------------------------------------------------------------------------------------|
| src/Cascader.tsx               | `ShowSearchType` 重命名为 `SearchConfig`,新增 `searchValue``onSearch``autoClearSearchValue` 属性;顶层同名属性标记废弃;组件内部通过 `useSearchConfig` 统一管理搜索配置。 |
| src/hooks/useSearchConfig.ts  | `useSearchConfig` 接口新增 `props` 参数,合并顶层废弃属性到返回的搜索配置中,类型从 `ShowSearchType` 更新为 `SearchConfig`|
| src/hooks/useSearchOptions.ts | 类型从 `ShowSearchType` 更新为 `SearchConfig`,无逻辑变更。                                              |
| src/index.tsx                 | 导出类型由 `ShowSearchType` 改为 `SearchConfig`|
| tests/search.spec.tsx          | 新增三条测试用例,验证 `showSearch` 下的 `onSearch` 回调、`searchValue` 绑定和 `autoClearSearchValue` 行为;修正部分测试中缺少的 `showSearch` 属性。 |
| README.md                     | 重构文档,将 `autoClearSearchValue` 从主表移除,整合到 `showSearch` 详细子属性说明中,新增 `showSearch` 属性描述和子属性说明。                |

## Sequence Diagram(s)

```mermaid
sequenceDiagram
    participant User
    participant Cascader
    participant useSearchConfig

    User->>Cascader: 输入搜索内容
    Cascader->>useSearchConfig: 获取合并后的搜索配置(showSearch + 顶层废弃属性)
    useSearchConfig-->>Cascader: 返回搜索配置对象
    Cascader->>Cascader: 根据配置更新搜索状态,调用 onSearch 回调
    Cascader-->>User: 展示搜索结果

Possibly related PRs

  • fix: antd-issue-51248 #541: 该PR也涉及 SearchConfig 接口扩展和 useSearchConfig 钩子的内部处理,二者均修改了搜索配置的合并逻辑。

Poem

🐇
搜索之风吹又起,
showSearch 配置新天地。
旧接口虽还在,
新用法更美丽。
代码整洁如春雨,
测试护航无忧虑。
兔子点头说可以!


<!-- walkthrough_end -->


---

<details>
<summary>📜 Recent review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**


<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between c438b45e269695df8ef3c8411fdc582ec9df857e and bbc72032f792ddadce4e847a5f0f6cb2c11725fa.

</details>

<details>
<summary>📒 Files selected for processing (1)</summary>

* `README.md` (1 hunks)

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🪛 markdownlint-cli2 (0.17.2)</summary>

<details>
<summary>README.md</summary>

244-244: Table column count
Expected: 5; Actual: 4; Too few cells, row will be missing data

(MD056, table-column-count)

</details>

</details>

</details>

</details>
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEYDEZyAAUASpETZWaCrKNxU3bABsvkCiQBHbGlcABpIcVwvOkgAIgAzEmouAFlKUnskigZYADU0L2DwtDx8AGFo5wBlLJz8wpJ0DHp8DBrnHJQMAgjYRsRYfAB3duzYSHj4Ei9aUNjIIbRkBwFmdRp6OV7G7ERKSABRNa9ZU4AZeGx0ZFtIDEcBfYBWAE4AZi7tvySxMCZmbitdgAegYSzBSj4/kBiHU+BcGhgfUYsEwGW0zGQPSYGEQ+C88Fo1EauGRJAAHkhxBgiJAAAZ7Dp5ArBOnhOklAgVLKjOoskhspr0OmtXmwOk8Cj4biUcTSLo9ND2eA06L0gbDMUSybTWiIuCNJSIBgUeDccStb6JfwYBjyzAoRAORrxKXML6YXBgI3wIhYaH4WEEFyQAAUSGddwe+zebwALAAOABMAEprgpuhTcBN4b1UIlqNh/IiAHL4dC0WjqeCtAqQJS4bReZC5+AA6JsbrUGtYRAyhjwSYMZDORq8fASQkxFVfI0ms0WjD65G3MFYR7fSckIYxahfACqNjOXFguFw3EQHGBwKI6lg2AEGn+wP8aF+/0B5G6oPBaEhwM8HxgVeN4NHMSwyhYTtcGWRxmGcVwDANfgMBOBRWHYFC82QQDfH8IIQgWJZIHgpRIC2Ukdj2Pg0HiBgAEYADY3nCIZBnsbAiFIRANgrKsaW+aIJE9Lp4nheDFwictKMgGwDgAQQAERSA4JngaJl1QNtuAJe1vn+TsiUknpsG4IySWRWh8AYRx2G7S0en8eJojEL4cjReUVVwKVaGwO1NnkNgKFvASGVqZkGkFDlSm5apwvqVlimaelRXCiUvOk5EGUGEY0rU3VS3LfBKL4Az2EQcICJ4nsKv4Pgq2NXZYVaZAd38fT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lMZr8v+BwnNbMN5A12tf05tveUGtlqt/66tQVKd6VIG2NGgPtm8oCxt+BhgBge0d6jcJ0NtQSV000fgaAd0d29BT08uVAr0m0H0O089/UB86gAA+oSIgOfcTFMDuLQOfdmm1Z9AvQmC8IxEmPRPRHGAxE8AIPRLQEmHGAAOzxBxgvAvBghgiMQvBxixhvDJj0TAMJhPB0QJhKi9QL0MBwMJgCBxhPAkBJgwMwNPC0DxAJgrVvAMAJhxhf3xC0AMBPDJiiAvBkMoPAONCYOn2qAMDANJgAAMbwSY8QwDLwSYlYf4docYJANDwDaAqD/D8QjEDAAgSYDESDSYqDGDx9J9EAZ9uAl9tA19t924dA59g020egQAA=== -->

<!-- internal state end -->
<!-- finishing_touch_checkbox_start -->

<details open="true">
<summary>✨ Finishing Touches</summary>

<details open="true">
<summary>🧪 Generate Unit Tests</summary>

- [ ] <!-- {"checkboxId": "f47ac10b-58cc-4372-a567-0e02b2c3d479", "radioGroupId": "utg-output-choice-group-unknown_comment_id"} -->   Create PR with Unit Tests
- [ ] <!-- {"checkboxId": "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "radioGroupId": "utg-output-choice-group-unknown_comment_id"} -->   Commit Unit Tests in branch `liuh-0514-showSerch`
- [ ] <!-- {"checkboxId": "07f1e7d6-8a8e-4e23-9900-8731c2c87f58", "radioGroupId": "utg-output-choice-group-unknown_comment_id"} -->   Post Copyable Unit Tests in Comment

</details>

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---

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.

<details>
<summary>❤️ Share</summary>

- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)
- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai)
- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai)
- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)

</details>

<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=react-component/cascader&utm_content=593):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Explain this complex logic.`
  - `Open a follow-up GitHub issue for this discussion.`
- Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples:
  - `@coderabbitai explain this code block.`
  -	`@coderabbitai modularize this function.`
- PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
  - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.`
  - `@coderabbitai read src/utils.ts and explain its main purpose.`
  - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.`
  - `@coderabbitai help me debug CodeRabbit configuration file.`

### Support

Need help? Create a ticket on our [support page](https://www.coderabbit.ai/contact-us/support) for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

### CodeRabbit Commands (Invoked using PR comments)

- `@coderabbitai pause` to pause the reviews on a PR.
- `@coderabbitai resume` to resume the paused reviews.
- `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
- `@coderabbitai full review` to do a full review from scratch and review all the files again.
- `@coderabbitai summary` to regenerate the summary of the PR.
- `@coderabbitai generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR.
- `@coderabbitai generate sequence diagram` to generate a sequence diagram of the changes in this PR.
- `@coderabbitai auto-generate unit tests` to generate unit tests for this PR.
- `@coderabbitai resolve` resolve all the CodeRabbit review comments.
- `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository.
- `@coderabbitai help` to get help.

### Other keywords and placeholders

- Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed.
- Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description.
- Add `@coderabbitai` anywhere in the PR title to generate the title automatically.

### CodeRabbit Configuration File (`.coderabbit.yaml`)

- You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository.
- Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json`

### Documentation and Community

- Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->

@afc163
Copy link
Member

afc163 commented May 14, 2025

README 里加一下。

@EmilyyyLiu EmilyyyLiu changed the title feat: Merge searchValue and onSearch into the showSearch field [WIP]feat: Merge searchValue and onSearch into the showSearch field May 14, 2025
@EmilyyyLiu EmilyyyLiu closed this May 15, 2025
@EmilyyyLiu EmilyyyLiu reopened this Jun 13, 2025
@EmilyyyLiu EmilyyyLiu changed the title [WIP]feat: Merge searchValue and onSearch into the showSearch field feat: Merge searchValue,autoClearSearchValue and onSearch into the showSearch field Jun 13, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
src/hooks/useSearchConfig.ts (1)

28-34: (searchConfig.limit as number) 的类型断言过于粗暴

limit 允许为 false,此处直接断言为 number 再比较会把 false 强制转换为 0,逻辑虽能工作,但易读性与类型安全均受损。可先判断类型再比较,避免断言。

-if ((searchConfig.limit as number) <= 0) {
+if (typeof searchConfig.limit === 'number' && searchConfig.limit <= 0) {

这样更符合预期语义,也无需类型断言。

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8962114 and c438b45.

📒 Files selected for processing (6)
  • README.md (1 hunks)
  • src/Cascader.tsx (4 hunks)
  • src/hooks/useSearchConfig.ts (2 hunks)
  • src/hooks/useSearchOptions.ts (1 hunks)
  • src/index.tsx (1 hunks)
  • tests/search.spec.tsx (2 hunks)
✅ Files skipped from review due to trivial changes (2)
  • src/index.tsx
  • src/hooks/useSearchOptions.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/search.spec.tsx
  • src/Cascader.tsx
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/hooks/useSearchConfig.ts (2)
src/index.tsx (2)
  • CascaderProps (7-7)
  • SearchConfig (9-9)
src/Cascader.tsx (2)
  • CascaderProps (157-175)
  • SearchConfig (43-69)
🪛 markdownlint-cli2 (0.17.2)
README.md

244-244: Table column count
Expected: 5; Actual: 4; Too few cells, row will be missing data

(MD056, table-column-count)


250-250: Table column count
Expected: 5; Actual: 4; Too few cells, row will be missing data

(MD056, table-column-count)


251-251: Table column count
Expected: 5; Actual: 4; Too few cells, row will be missing data

(MD056, table-column-count)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: WIP
🔇 Additional comments (1)
src/hooks/useSearchConfig.ts (1)

6-6: 避免使用 any,加强类型安全

props?: any 失去 TypeScript 带来的约束价值。可使用 Partial<Pick<CascaderProps, ...>> 精确声明,只暴露当前 hook 真实依赖的字段,既防止误用又提升 IDE 提示。
[ suggest_optional_refactor ]

Comment on lines +6 to +8
export default function useSearchConfig(showSearch?: CascaderProps['showSearch'], props?: any) {
const { autoClearSearchValue, searchValue, onSearch } = props;
return React.useMemo<[boolean, SearchConfig]>(() => {
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

props 解构存在潜在运行时异常

props 为空或未传入时,const { autoClearSearchValue, searchValue, onSearch } = props; 会直接对 undefined 进行解构,运行时将抛出 TypeError: Cannot destructure property ... of 'undefined' or 'null'.
建议在形参或解构处增加默认值,避免意外崩溃。

-export default function useSearchConfig(showSearch?: CascaderProps['showSearch'], props?: any) {
-  const { autoClearSearchValue, searchValue, onSearch } = props;
+export default function useSearchConfig(
+  showSearch?: CascaderProps['showSearch'],
+  props: Partial<Pick<CascaderProps, 'autoClearSearchValue' | 'searchValue' | 'onSearch'>> = {},
+) {
+  const { autoClearSearchValue, searchValue, onSearch } = props;

这样既提供了类型约束,也为缺省情况兜底。

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export default function useSearchConfig(showSearch?: CascaderProps['showSearch'], props?: any) {
const { autoClearSearchValue, searchValue, onSearch } = props;
return React.useMemo<[boolean, SearchConfig]>(() => {
export default function useSearchConfig(
showSearch?: CascaderProps['showSearch'],
props: Partial<Pick<CascaderProps, 'autoClearSearchValue' | 'searchValue' | 'onSearch'>> = {},
) {
const { autoClearSearchValue, searchValue, onSearch } = props;
return React.useMemo<[boolean, SearchConfig]>(() => {
// …rest of implementation
});
}
🤖 Prompt for AI Agents
In src/hooks/useSearchConfig.ts around lines 6 to 8, the destructuring of props
without a default value can cause a runtime TypeError if props is undefined or
null. To fix this, provide a default empty object for props either in the
function parameter (e.g., props = {}) or during destructuring to ensure safe
access to its properties and prevent crashes.

README.md Outdated
Comment on lines 231 to 236
<tr>
<td>showSearch</td>
<td>Boolean | Object</td>
<td>>false</td>
<td>hide popup on select</td>
</tr>
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

showSearch 行描述与含义不符且默认值箭头错误

  1. 描述 “hide popup on select” 与搜索功能毫无关联,应改为 “启用搜索或自定义搜索配置”。
  2. > 字符应去掉;表格默认值应直接写 false
-<td>showSearch</td>
-<td>Boolean | Object</td>
-<td>>false</td>
-<td>hide popup on select</td>
+<td>showSearch</td>
+<td>boolean | object</td>
+<td>false</td>
+<td>启用搜索功能或传入搜索配置对象</td>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<tr>
<td>showSearch</td>
<td>Boolean | Object</td>
<td>>false</td>
<td>hide popup on select</td>
</tr>
<tr>
<td>showSearch</td>
<td>boolean | object</td>
<td>false</td>
<td>启用搜索功能或传入搜索配置对象</td>
</tr>
🤖 Prompt for AI Agents
In README.md around lines 231 to 236, the description for the showSearch
property is incorrect and the default value formatting is wrong. Change the
description from "hide popup on select" to "启用搜索或自定义搜索配置" to accurately reflect
its purpose. Also, remove the '>' character before false in the default value
column so it simply shows "false".

Copy link

codecov bot commented Jun 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.83%. Comparing base (e3ade1a) to head (bbc7203).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #593   +/-   ##
=======================================
  Coverage   99.83%   99.83%           
=======================================
  Files          23       23           
  Lines         611      612    +1     
  Branches      176      176           
=======================================
+ Hits          610      611    +1     
  Misses          1        1           

☔ View full report in Codecov by Sentry.
📢 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.

@zombieJ zombieJ merged commit a10f879 into react-component:master Jun 13, 2025
11 checks passed
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