You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: respect disableCheckbox and checkable=false on Enter key - #693
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 键激活禁用复选框或不可勾选的节点时,不会触发变更;激活可勾选节点时,变更回调会收到正确的选中值和标签。
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: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
标题“fix: respect disableCheckbox and checkable=false on Enter key”准确描述了主要变更:在 treeCheckable 模式下按 Enter 时,OptionList 现在传递完整节点属性,使 disableCheckbox 与 checkable=false 节点无法被勾选。摘要和目标说明与此一致,标题未包含无关内容。
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
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.
兔子轻敲 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
treeCheckable, pressing Enter on the active option in the open dropdown checked the node even when it hasdisableCheckboxorcheckable: false, which a mouse click ignores.onInternalSelecthas the guard (checkable && isCheckDisabled(node)), andisCheckDisabledreadsdisableCheckboxandcheckablefrom the node it receives. A mouse click passes the whole tree node. The Enter key handler inOptionListpassed only{ key: activeKey }, so the guard never saw those flags and the node was checked (onChangefired).The Enter handler now passes
{ ...activeEntity.node, key: activeKey }, the same node data a click has, so the existing guard applies. Nothing else changes:disabledandselectable: falsewere already handled in that handler.Test:
should not check disableCheckbox or checkable=false node with Enter keyintests/Select.checkable.spec.tsxpresses Enter on adisableCheckboxnode and acheckable: falsenode (noonChange), then on a normal node (onChangecalled with['normal']). It fails onmaster(onChangeexpected 0 calls, received 1) and passes now.npx rc-testpasses (13 suites, 188 tests), andtsc --noEmitand ESLint onsrc/OptionList.tsxare clean. Prettier reports style differences insrc/OptionList.tsxonmastertoo (not in the changed lines), so I left the formatting as is.Summary by CodeRabbit