Skip to content

fix: respect disableCheckbox and checkable=false on Enter key - #693

Open
mokshupadhyay wants to merge 1 commit into
react-component:masterfrom
mokshupadhyay:fix/enter-disable-checkbox
Open

mokshupadhyay wants to merge 1 commit into
react-component:masterfrom
mokshupadhyay:fix/enter-disable-checkbox

Conversation

@mokshupadhyay

@mokshupadhyay mokshupadhyay commented Dec 1, 2026 •

Copy link
Copy Markdown

With treeCheckable, pressing Enter on the active option in the open dropdown checked the node even when it has disableCheckbox or checkable: false, which a mouse click ignores.

onInternalSelect has the guard (checkable && isCheckDisabled(node)), and isCheckDisabled reads disableCheckbox and checkable from the node it receives. A mouse click passes the whole tree node. The Enter key handler in OptionList passed only { key: activeKey }, so the guard never saw those flags and the node was checked (onChange fired).

The Enter handler now passes { ...activeEntity.node, key: activeKey }, the same node data a click has, so the existing guard applies. Nothing else changes: disabled and selectable: false were already handled in that handler.

Test: should not check disableCheckbox or checkable=false node with Enter key in tests/Select.checkable.spec.tsx presses Enter on a disableCheckbox node and a checkable: false node (no onChange), then on a normal node (onChange called with ['normal']). It fails on master (onChange expected 0 calls, received 1) and passes now. npx rc-test passes (13 suites, 188 tests), and tsc --noEmit and ESLint on src/OptionList.tsx are clean. Prettier reports style differences in src/OptionList.tsx on master too (not in the changed lines), so I left the formatting as is.

Summary by CodeRabbit

  • 问题修复
    • 修复按 Enter 键选择节点时节点信息不完整的问题,现在会保留当前活动节点的属性。
    • 在可勾选树中,按 Enter 键激活禁用复选框或不可勾选的节点时,不会触发变更;激活可勾选节点时,变更回调会收到正确的选中值和标签。

@vercel

vercel Bot commented Dec 1, 2026

Copy link
Copy Markdown

@mokshupadhyay 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 Dec 1, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Enter 键触发选择时,onInternalSelect 现在接收当前活动节点的完整属性,并以 activeKey 覆盖节点的 key。新增测试覆盖不可勾选节点与普通可勾选节点的键盘交互和回调参数。

Changes

键盘选择行为

Layer / File(s) Summary
Enter 键选择与验证
src/OptionList.tsx, tests/Select.checkable.spec.tsx
Enter 键选择时,node 参数改为包含当前活动节点的完整属性,并使用 activeKey 作为 key。新增测试验证 disableCheckbox 和 checkable: false 节点不会触发 onChange,普通可勾选节点会传递预期回调参数。

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

Change: Bug fix

Suggested reviewers: zombiej

Merge Risk: Minimal · up to b7ff3

Pressing Enter on a tree node that is not checkable or has its checkbox disabled will no longer check it, matching mouse-click behavior. The change is small and covered by a new test, so merge risk is minimal.

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: respect disableCheckbox and checkable=false on Enter key”准确描述了主要变更:在 treeCheckable 模式下按 Enter 时,OptionList 现在传递完整节点属性,使 disableCheckbox 与 checkable=false 节点无法被勾选。摘要和目标说明与此一致,标题未包含无关内容。
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.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • 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: c0f5fc1f-b0fb-44d7-890f-067c0035706e
Commits

Reviewing files that changed from the base of the PR and between 0fbfa68 and b7ff37b.

Files selected for processing: 2

  • src/OptionList.tsx
  • tests/Select.checkable.spec.tsx

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

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.

1 participant