Skip to content

Conversation

@zombieJ
Copy link
Member

@zombieJ zombieJ commented Dec 17, 2025

https://codesandbox.io/p/sandbox/ji-ben-shi-yong-antd-6-1-1-forked-n83xdl?file=%2Fdemo.tsx%3A14%2C18

Summary by CodeRabbit

发布说明

  • 新功能

    • Select 组件现已支持 defaultOpen 属性,允许指定下拉菜单的初始打开状态。
  • 测试

    • 添加测试用例以验证 defaultOpen 功能的正确性。

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Dec 17, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
select Ready Ready Preview, Comment Dec 17, 2025 8:53am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 17, 2025

功能概览

修改 useOpen 钩子的签名,将 defaultOpen: boolean 参数添加为第一个参数,使得未控制状态的 Select 组件在初始化时能够遵循显式的 defaultOpen 值,而非始终默认为 false

变更详情

文件组 / 文件 变更摘要
useOpen 钩子 API 更新
src/hooks/useOpen.ts
将公开函数签名从 useOpen(propOpen, onOpen, postOpen) 更改为 useOpen(defaultOpen, propOpen, onOpen, postOpen)useControlledState 的初始化从硬编码的 false 改为使用 defaultOpen 参数
BaseSelect 调用点更新
src/BaseSelect/index.tsx
调整对 useOpen 的调用,将 defaultOpen 作为新的第一参数传入,保持后续参数和选通逻辑不变
功能验证测试
tests/Select.test.tsx
Select.Basic 下新增测试用例 "should defaultOpen work",验证携带 defaultOpen 的 Select 组件下拉菜单是否正确打开

预估代码审查工作量

🎯 2 (Simple) | ⏱️ ~12 分钟

  • src/hooks/useOpen.ts:公开 API 签名变更需确认所有调用点均已正确适配新参数顺序
  • src/BaseSelect/index.tsx:验证 defaultOpen 值的传递是否符合业务逻辑,特别是与禁用/空列表等状态的交互
  • tests/Select.test.tsx:确保新测试用例涵盖 defaultOpentruefalse 两种场景

可能相关的 PR

庆祝诗篇

🐰 默认值春风来,Open 钩子焕新彩
defaultOpen 添首位,控制流终成体
测试验证已备好,稳定运行无挂碍
小兔跳跃庆此时,Select 组件更通泰

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题清晰简洁地概括了主要变更,即修复 defaultOpen 功能不工作的问题,与代码变更完全相关。
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-default-open

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 and usage tips.

@gemini-code-assist
Copy link

Summary of Changes

Hello @zombieJ, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves an issue where the 'defaultOpen' prop was not correctly initializing the open state of select components. The underlying 'useOpen' hook has been updated to properly consume and apply this prop, ensuring that components render with the expected initial open state. The change is validated with a new dedicated test case.

Highlights

  • Fix defaultOpen prop: The 'defaultOpen' prop for the BaseSelect component was not functioning as expected, preventing components from being initially open when specified.
  • Update useOpen hook: The 'useOpen' hook now accepts a 'defaultOpen' parameter, which is used to initialize the component's open state via 'useControlledState'.
  • New test case: A new test has been added to 'Select.test.tsx' to ensure that the 'defaultOpen' prop correctly sets the initial open state of the Select component.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov
Copy link

codecov bot commented Dec 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.42%. Comparing base (11d5ca7) to head (c45febc).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1187   +/-   ##
=======================================
  Coverage   99.42%   99.42%           
=======================================
  Files          31       31           
  Lines        1215     1216    +1     
  Branches      432      433    +1     
=======================================
+ Hits         1208     1209    +1     
  Misses          7        7           

☔ 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.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

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 correctly fixes an issue where the defaultOpen prop was not working. The fix involves passing the defaultOpen prop to the useOpen hook, which then correctly initializes the component's open state. The implementation is clean and effective. I also appreciate the addition of a new test case to verify the functionality, which is great for preventing future regressions. I've added one comment regarding a minor type inconsistency for improved type safety and code clarity.

Comment on lines +361 to 366
const [mergedOpen, triggerOpen] = useOpen(
defaultOpen || false,
open,
onPopupVisibleChange,
(nextOpen) => (disabled || emptyListContent ? false : nextOpen),
);

Choose a reason for hiding this comment

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

medium

The signature of the useOpen hook in src/hooks/useOpen.ts has a type inconsistency. The propOpen parameter is typed as boolean, but it receives the open prop from here, which is of type boolean | undefined. To ensure type safety and correctness, the hook's signature should be updated to propOpen?: boolean in src/hooks/useOpen.ts. This will accurately reflect that the open prop is optional.

Copy link
Contributor

@crazyair crazyair left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@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: 0

🧹 Nitpick comments (1)
src/BaseSelect/index.tsx (1)

361-366: 正确实现了 defaultOpen 支持!

defaultOpen 作为第一个参数传递给 useOpen 钩子的修改是正确的,这使得初始打开状态能够正确设置。

可选的小优化:defaultOpen || false 中的 || false 可以省略,因为 useControlledState 应该能够正确处理 undefined 值。不过当前的写法更加明确,也完全可以接受。

可选的简化建议:

  const [mergedOpen, triggerOpen] = useOpen(
-    defaultOpen || false,
+    defaultOpen,
    open,
    onPopupVisibleChange,
    (nextOpen) => (disabled || emptyListContent ? false : nextOpen),
  );
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 11d5ca7 and c45febc.

📒 Files selected for processing (3)
  • src/BaseSelect/index.tsx (1 hunks)
  • src/hooks/useOpen.ts (2 hunks)
  • tests/Select.test.tsx (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
tests/Select.test.tsx (1)
tests/utils/common.ts (1)
  • expectOpen (4-20)
src/BaseSelect/index.tsx (1)
src/hooks/useOpen.ts (1)
  • useOpen (41-99)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (2)
tests/Select.test.tsx (1)

69-77: 测试用例正确验证了 defaultOpen 功能!

该测试用例简洁明了,正确验证了 defaultOpen 属性使下拉菜单初始时处于打开状态的功能。测试逻辑清晰,符合项目的测试模式。

src/hooks/useOpen.ts (1)

42-42: 正确实现了 defaultOpen 参数支持!

函数签名更新和状态初始化的修改都是正确的:

  1. Line 42:将 defaultOpen 作为第一个参数添加到函数签名中,符合 React 约定(defaultValuevalue 之前)
  2. Line 54:将 defaultOpen 传递给 useControlledState,使得在非受控模式下能够使用 defaultOpen 初始化打开状态

这个修改正确地解决了 defaultOpen 不生效的问题,同时保持了 SSR 安全性和受控/非受控状态的逻辑。

Also applies to: 54-54

@zombieJ zombieJ merged commit db0141a into master Dec 17, 2025
12 checks passed
@zombieJ zombieJ deleted the fix-default-open branch December 17, 2025 09:00
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