Skip to content

fix: clear enter lock when select is disabled - #1248

Open
dogledogle wants to merge 2 commits into
react-component:masterfrom
dogledogle:fix/clear-enter-lock-on-disable
Open

dogledogle wants to merge 2 commits into
react-component:masterfrom
dogledogle:fix/clear-enter-lock-on-disable

Conversation

@dogledogle

@dogledogle dogledogle commented Aug 21, 2026 •

Copy link
Copy Markdown

修复 Select 在异步更新过程中被设为 disabled 后,Enter 键状态未正确重置的问题。

当用户通过搜索并按 Enter 选择选项时,如果 onChange 中立即将 Select 设为 disabled,输入框可能不会触发后续的 keyup 或 blur 事件,导致 Enter 锁状态残留。重新启用 Select 后,用户需要按两次 Enter 才能完成下一次选择。

本次修改会在 Select 进入 disabled 状态时主动清理 Enter 锁,并新增回归测试,确保连续搜索选择只需按一次 Enter。

相关 issue:#51716

Summary by CodeRabbit

  • 新功能

    • Select 新增 autoComplete 属性,可自定义自动完成设置。
  • 问题修复

    • 修复 Select 在 Enter 操作过程中被禁用后,键盘锁定状态未清除的问题。
    • 重新启用后,可继续搜索并按 Enter 依次选择选项。
  • 测试

    • 增加禁用、重新启用及后续选择流程的测试覆盖。

@vercel

vercel Bot commented Aug 21, 2026

Copy link
Copy Markdown

@dogledogle 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 Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Select 进入禁用状态时,会将 Enter 键锁定标志重置为 false,然后关闭下拉框并清除焦点状态。新增的回归测试覆盖 keyup 中断后重新启用 Select 并继续使用 Enter 选择选项的流程。

Changes

Select 键盘交互

Layer / File(s) Summary
禁用状态清理与回归验证
src/BaseSelect/index.tsx, tests/Select.test.tsx
禁用状态处理将 keyLockRef.current 重置为 false。回归测试覆盖搜索、Enter 选择、禁用后重新启用,以及 [3, 2, 1] 的 onChange 调用顺序。

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: Minimal · up to 7e704

Disabling the Select now clears the stale Enter lock, so selecting an option after re-enabling needs only one Enter press. The change is small, a regression test covers it, and no merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 标题“fix: clear enter lock when select is disabled”描述了本 PR 的主要改动:Select 被禁用时清除 Enter 键锁。变更摘要显示 src/BaseSelect/index.tsx 在禁用副作用中将 keyLockRef.current 重置为 false,并新增测试覆盖连续搜索并按 Enter 选择的场景。标题与变更集及 PR 目标一致,且简…
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.
Full details: Title check

Explanation

标题“fix: clear enter lock when select is disabled”描述了本 PR 的主要改动:Select 被禁用时清除 Enter 键锁。变更摘要显示 src/BaseSelect/index.tsx 在禁用副作用中将 keyLockRef.current 重置为 false,并新增测试覆盖连续搜索并按 Enter 选择的场景。标题与变更集及 PR 目标一致,且简洁明确。

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

我是小兔,轻敲 Enter 键,
锁标志清零,下拉框轻轻合上。
搜索选项,再按一次回车,
一、二、三,选择依序回响。
新测试守着这段键盘旅程,
我蹦过代码,月光照耳尖。

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 289fc7c8-6b56-4065-8e6c-471466c827b1
Commits

Reviewing files that changed from the base of the PR and between d43c729 and 7e704f8.

Files selected for processing: 1

  • src/BaseSelect/index.tsx

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@nrps9909 nrps9909 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.

Approved exact head 6449ac52419fbd2ef278a4809ba2fb4ed1dfeea6.

The reset is correctly scoped to the existing disabled-state effect: an interrupted Enter interaction clears only the stale selection lock while the same effect already closes the popup and removes focus. Re-enabling the Select therefore restores the first Enter selection without changing ordinary keyup/blur handling.

The complete repository passes 21/21 suites, 437/437 tests, and 21/21 snapshots. TypeScript, ESM/CJS/declaration builds, Less compilation, and lint with zero errors also pass; the reported warnings are existing hook/demo warnings outside this three-line behavior change.

I additionally performed a causal base/head check with the submitted regression. Removing only the new lock reset made the expected [3, 2, 1] selection sequence fail as [3, 2], proving that the first post-enable Enter remained swallowed. Restoring the exact head made the same focused regression pass.

The only remote failure is the fork Vercel authorization gate, not a source check.

Codex-assisted review: Codex traced the Enter lock lifecycle, ran the complete repository and build validation, and executed the isolated causal reversal against the exact head. No repository files were changed.

@dogledogle
dogledogle force-pushed the fix/clear-enter-lock-on-disable branch from 6449ac5 to d43c729 Compare September 10, 2026 05:22

This branch has not been deployed

No deployments
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