Skip to content

Conversation

@zombieJ
Copy link
Member

@zombieJ zombieJ commented Oct 21, 2025

triggerOpen 只对 blur 造成关闭进行延迟操作,以优化相应逻辑。

Summary by CodeRabbit

  • Refactor
    • 优化了选择器组件在弹出窗口交互中的打开触发逻辑,改进了延迟加载和状态管理的处理机制,提升了用户界面响应性能。

@vercel
Copy link

vercel bot commented Oct 21, 2025

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

Project Deployment Preview Comments Updated (UTC)
select Ready Ready Preview Comment Oct 21, 2025 4:01pm

💡 Enable Vercel Agent with $100 free credit for automated AI reviews

@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 refactors the triggerOpen function to accept a configuration object, introducing a new lazy option. This lazy option is then applied within the BaseSelect component's blur handling to delay the closing of the dropdown, which optimizes the interaction logic and provides a smoother user experience, especially in scenarios involving rapid focus changes.

Highlights

  • Refactored triggerOpen Signature: The triggerOpen function now accepts an optional configuration object as its second argument, allowing for more structured passing of options like ignoreNext and the newly introduced lazy flag.
  • Introduced lazy Option for Closing: A new lazy: true option has been added to the triggerOpen function, specifically utilized when the select component loses focus (on blur). This option allows for delaying the closing action.
  • Optimized Blur-Triggered Closing Logic: The useOpen hook's toggleOpen implementation has been updated to leverage the lazy option. When lazy is true and the intent is to close, the triggerEvent is not called immediately, thereby optimizing the response to blur events and improving user experience.
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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 21, 2025

综述

该变更修改了 triggerOpen 函数的参数签名,将第二个布尔参数改为配置对象,支持 ignoreNextlazy 标志。相应更新了调用点和处理逻辑以适应新的参数结构。

变更

文件内容 变更摘要
类型定义与钩子实现
src/hooks/useOpen.ts
TriggerOpenType 类型从 (nextOpen?: boolean, ignoreNext?: boolean) => void 改为 (nextOpen?: boolean, config?: { ignoreNext?: boolean; lazy?: boolean; }) => voidtoggleOpen 处理程序更新为解析配置对象(默认值为 { ignoreNext: false, lazy: false });打开状态变更的触发逻辑调整为在 nextOpenVal 为真或 lazy 为假时触发
选择器组件调用
src/BaseSelect/index.tsx
onBlur 事件调用 triggerOpen 时添加 lazy: true 配置;鼠标按下在弹窗内部时用配置对象 { ignoreNext: true } 替代布尔标志调用 triggerOpen

序列图

由于此变更主要涉及函数签名和参数传递的重构,不涉及控制流的实质性改变,因此不生成序列图。

预估代码审查工作量

🎯 2 (简单) | ⏱️ ~12 分钟

变更范围聚焦在两个相关文件,改动遵循一致的模式(参数从布尔值改为配置对象),逻辑更新直观清晰,无复杂分支判断或多个独立的设计决策。

诗歌

🐰 配置对象润似云,
布尔参数化作灵,
懒加载与忽略次,
精妙标志齐翔起,
代码流畅如兔奔!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed 标题"chore: adjust open order"与changeset的主要变更相关。根据summary信息,PR对触发打开逻辑进行了优化和调整,包括为triggerOpen添加了新的配置选项(lazyignoreNext),以及更新了打开状态变更的触发逻辑。标题准确地概括了这些调整的本质——调整打开操作的顺序。虽然标题相对简洁,但它清晰且足以让团队成员理解主要变更的方向。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ 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 adjust

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.

@codecov
Copy link

codecov bot commented Oct 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.41%. Comparing base (208c66a) to head (9a1b732).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1169   +/-   ##
=======================================
  Coverage   99.41%   99.41%           
=======================================
  Files          31       31           
  Lines        1192     1194    +2     
  Branches      422      424    +2     
=======================================
+ Hits         1185     1187    +2     
  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

The pull request modifies the triggerOpen function in src/hooks/useOpen.ts to accept a configuration object with ignoreNext and lazy options. This change allows for more fine-grained control over when the dropdown is opened or closed, specifically adding a delay for blur events and preventing immediate closure when clicking within the popup. The BaseSelect component in src/BaseSelect/index.tsx is updated to utilize these new options when calling triggerOpen in onInternalBlur and onInternalMouseDown.

Comment on lines +25 to +31
export type TriggerOpenType = (
nextOpen?: boolean,
config?: {
ignoreNext?: boolean;
lazy?: boolean;
},
) => void;

Choose a reason for hiding this comment

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

high

The type definition for TriggerOpenType has been updated to include a config object with ignoreNext and lazy properties. Ensure that all usages of TriggerOpenType are updated to reflect this change.

Comment on lines 572 to +575
if (!disabled) {
triggerOpen(false);
triggerOpen(false, {
lazy: true,
});

Choose a reason for hiding this comment

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

medium

The triggerOpen function is now called with a lazy option set to true. This introduces a delay in closing the dropdown on blur. Ensure this delay does not negatively impact the user experience, especially in scenarios where immediate feedback is expected.

Comment on lines 586 to +589
// Tell `open` not to close since it's safe in the popup
triggerOpen(true, true);
triggerOpen(true, {
ignoreNext: true,
});

Choose a reason for hiding this comment

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

medium

The triggerOpen function is called with ignoreNext: true when clicking inside the popup. This prevents the dropdown from closing immediately. Verify that this behavior is consistent with the intended user experience and doesn't introduce unexpected side effects.

Comment on lines +70 to +72
const toggleOpen = useEvent<TriggerOpenType>((nextOpen, config = {}) => {
const { ignoreNext = false, lazy = false } = config;

Choose a reason for hiding this comment

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

medium

The toggleOpen function now accepts a config object. The default values for ignoreNext and lazy are set to false. This is good for backward compatibility, but ensure that all call sites are reviewed to determine if these options should be explicitly set.

Comment on lines +79 to 91
if (nextOpenVal || !lazy) {
if (!taskLockRef.current) {
triggerEvent(nextOpenVal);

// Lock if needed
if (ignoreNext) {
taskLockRef.current = ignoreNext;

macroTask(() => {
taskLockRef.current = false;
}, 2);
}
}

Choose a reason for hiding this comment

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

medium

The logic for opening the dropdown has been modified to include a check for the lazy option. If nextOpenVal is true or lazy is false, the dropdown is opened immediately (if not locked). This change affects the timing of dropdown opening. Consider adding a comment explaining the rationale behind this change.

Comment on lines 95 to +97
macroTask(() => {
if (id === taskIdRef.current && !taskLockRef.current) {
triggerEvent(false);
triggerEvent(nextOpenVal);

Choose a reason for hiding this comment

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

medium

The logic for closing the dropdown is now executed within a macroTask. This introduces a delay in closing the dropdown. Ensure that this delay does not negatively impact the user experience, especially in scenarios where immediate feedback is expected.

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/hooks/useOpen.ts (1)

79-93: 建议添加注释说明延迟逻辑。

第 79 行的条件 if (nextOpenVal || !lazy) 实现了正确的行为:

  • 打开操作 (nextOpenVal=true) 始终立即触发
  • 关闭操作 + lazy=false 立即触发
  • 关闭操作 + lazy=true 延迟到宏任务执行

这与 PR 目标一致,但建议添加注释解释此逻辑,以提高代码可读性。

应用此差异添加说明性注释:

+    // Trigger immediately when opening or when not lazy
+    // Lazy mode only defers closing operations
     if (nextOpenVal || !lazy) {
       if (!taskLockRef.current) {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 208c66a and 9a1b732.

📒 Files selected for processing (2)
  • src/BaseSelect/index.tsx (2 hunks)
  • src/hooks/useOpen.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/hooks/useOpen.ts (1)
tests/utils/common.ts (1)
  • toggleOpen (22-31)
🔇 Additional comments (4)
src/hooks/useOpen.ts (2)

25-31: 类型定义清晰,向后兼容性良好。

新的配置对象方式比原来的布尔参数更具扩展性,且通过可选参数保持了向后兼容。


70-100: 所有调用点已正确更新,向后兼容性得到维护。

验证完成。代码库中所有 toggleOpen 调用都与新签名兼容:

  • 单参数调用 (toggleOpen(true), toggleOpen(false), toggleOpen()) 通过默认参数 config = {} 正确处理
  • 配置对象调用 (toggleOpen(false, { lazy: true }), toggleOpen(true, { ignoreNext: true })) 正确传递配置
  • 在 src/BaseSelect/index.tsx、src/SelectInput/index.tsx、src/OptionList.tsx 等文件的所有 17+ 个调用点中未发现不兼容的用法

实现逻辑正确,ignoreNextlazy 参数的默认值确保了向后兼容性,同时支持新的配置对象语法。

src/BaseSelect/index.tsx (2)

572-578: blur 延迟关闭优化实现正确。

使用 { lazy: true } 延迟 blur 触发的关闭操作,允许用户在失焦后点击下拉框而不会立即关闭,这正是 PR 目标所述的优化。


585-590: popup 内点击的防关闭逻辑正确。

使用 { ignoreNext: true } 在点击 popup 内元素时设置锁,阻止延迟的 blur 关闭操作执行。与 lazy 选项配合良好,确保用户点击 popup 时不会意外关闭。

@zombieJ zombieJ merged commit 57541aa into master Oct 21, 2025
12 checks passed
@zombieJ zombieJ deleted the adjust branch October 21, 2025 16:06
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.

2 participants