feat: support checkStrictly for independent parent/child checking - #662
feat: support checkStrictly for independent parent/child checking#662EmilyyyLiu wants to merge 1 commit into
Conversation
Add a `checkStrictly` prop to Cascader (and Panel) that, when combined with `checkable`, makes parent and children nodes checked independently: no descendant conduction, no half-checked state. `showCheckedStrategy` is ignored in this mode. Single-select mode is unaffected. - Add `checkStrictly` prop with JSDoc, thread through useValues/useSelect - useValues: skip conductCheck under checkStrictly (no half-checked) - useSelect: precise path toggle without roll-up under checkStrictly - deDuplicatedValues: bypass formatStrategyValues under checkStrictly - Tests: 7 checkStrictly cases incl. disabled-sibling contrast and controlled value round-trip - README API table + demo (examples/multiple-strict.tsx) Closes ant-design/ant-design#38049 Co-Authored-By: Claude <noreply@anthropic.com>
|
Someone is attempting to deploy a commit to the React Component Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (8)
Included review availability: Your plan includes up to 2 reviews per rolling hour; 1 remains after this review. WalkthroughCascader 新增 Changes严格级联选择
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to This PR adds independent parent/child selection for strict multi-select mode while preserving existing behavior by default; no actionable merge-blocking risk remains beyond normal checks and review. Sequence Diagram(s)sequenceDiagram
participant Cascader
participant Panel
participant useValues
participant useSelect
Cascader->>Panel: 传递 checkStrictly
Panel->>useValues: 计算独立选中值
Panel->>useSelect: 处理当前路径
useSelect-->>Cascader: 返回独立选中路径
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #662 +/- ##
=======================================
Coverage 99.39% 99.40%
=======================================
Files 22 22
Lines 661 670 +9
Branches 203 212 +9
=======================================
+ Hits 657 666 +9
Misses 4 4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
nrps9909
left a comment
There was a problem hiding this comment.
Reviewed exact head 31e66b1b1344faf1d78192919867c8c69d84f450.
The strict path bypasses conduction and strategy roll-up only in checkable mode, while preserving the existing single-select and default non-strict paths. I also verified that independently selected parent and child paths can coexist and that removing the parent leaves the child selected; the same behavior works through Cascader.Panel.
Validation performed:
- Repository test suite: 126 passed, 2 skipped, 3 snapshots.
- Independent behavior probe: 3 passed, covering parent/child removal independence, the Panel path, and single-select isolation; rerunning the full suite with the probe produced 129 passed and 2 skipped.
- TypeScript (
tsc --noEmit) and both ESM/CJSfather buildoutputs: passed. - Repository ESLint: 0 errors (6 existing warnings outside this diff);
git diff --check: clean. - Functional CI is green: component tests, React Doctor, CodeQL, coverage, Socket, WIP, and Surge preview. The lone Vercel status says
Authorization required to deploy; this is external preview authorization, while the repository's Surge preview succeeded.
I found no blocking correctness issue in this change.
AI assistance disclosure: Codex was used to inspect the exact-head diff and review history, run the test/build/static-check matrix and independent behavior probes, audit live CI, and draft this review. I independently verified the conclusions.
Background
ref ant-design/ant-design#38049
antd Cascader(在
multiple模式下)目前勾选父子节点是联动的:勾父自动勾全部子孙、子全勾则自动归并到父。部分场景(如省/市独立选择)需要父子勾选解耦。antd 维护者 afc163 在该 issue 中已确认接受此特性并邀请 PR。本 PR 在 rc-cascader 底层新增
checkStrictlyprop,使父子勾选状态独立。antd 上层可将其以multiple={{ checkStrictly: true }}形式映射封装。Changes
checkStrictly?: booleanprop(Cascader + Panel),默认false,仅在checkable(多选)下生效,单选模式无影响。useValues:strict 模式跳过conductCheck,无半选态(halfChecked恒为[])。useSelect:strict 模式精确 toggle 当前 path,不走传导与showCheckedStrategyroll-up。deDuplicatedValues:strict 模式绕过formatStrategyValues(showCheckedStrategy被忽略)。Isolation / No side effects
if (checkStrictly) {...} else { 原逻辑 },默认值undefined/false走else,与改动前行为等价。if (!multiple) return之后。checkStrictly在解构阶段取出,不透传给@rc-component/select的BaseSelect,不污染 DOM。halfCheckedValues在 strict 下恒空 → 无 indeterminate 渲染,不影响disableCheckbox/disabled既有逻辑。conductCheck正确消化,反之亦然,切换无脏数据。Tests
新增 7 个
checkStrictly用例(tests/checkable.spec.tsx):showCheckedStrategy被忽略valueround-trip全量
rc-test:126 passed / 2 skipped。tsc --noEmit通过。Docs
checkStrictly行。examples/multiple-strict.tsx+docs/demo/multiple-strict.md。🤖 Generated with Claude Code
Summary by CodeRabbit
新功能
checkStrictly属性,支持父子节点独立勾选,适用于多选级联场景。文档
checkStrictly、styles、optionRender等内容。测试