Skip to content

feat: support checkStrictly for independent parent/child checking - #662

Open
EmilyyyLiu wants to merge 1 commit into
react-component:masterfrom
EmilyyyLiu:liuh-checkStrictly
Open

feat: support checkStrictly for independent parent/child checking#662
EmilyyyLiu wants to merge 1 commit into
react-component:masterfrom
EmilyyyLiu:liuh-checkStrictly

Conversation

@EmilyyyLiu

@EmilyyyLiu EmilyyyLiu commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Background

ref ant-design/ant-design#38049

antd Cascader(在 multiple 模式下)目前勾选父子节点是联动的:勾父自动勾全部子孙、子全勾则自动归并到父。部分场景(如省/市独立选择)需要父子勾选解耦。antd 维护者 afc163 在该 issue 中已确认接受此特性并邀请 PR。

本 PR 在 rc-cascader 底层新增 checkStrictly prop,使父子勾选状态独立。antd 上层可将其以 multiple={{ checkStrictly: true }} 形式映射封装。

Changes

  • checkStrictly?: boolean prop(Cascader + Panel),默认 false,仅在 checkable(多选)下生效,单选模式无影响。
  • useValues:strict 模式跳过 conductCheck,无半选态(halfChecked 恒为 [])。
  • useSelect:strict 模式精确 toggle 当前 path,不走传导与 showCheckedStrategy roll-up。
  • deDuplicatedValues:strict 模式绕过 formatStrategyValuesshowCheckedStrategy 被忽略)。

Isolation / No side effects

  • 非-strict 路径逐字未改:三处均为 if (checkStrictly) {...} else { 原逻辑 },默认值 undefined/falseelse,与改动前行为等价。
  • 单选模式不受影响:strict 短路均在 if (!multiple) return 之后。
  • checkStrictly 在解构阶段取出,不透传给 @rc-component/selectBaseSelect,不污染 DOM。
  • halfCheckedValues 在 strict 下恒空 → 无 indeterminate 渲染,不影响 disableCheckbox/disabled 既有逻辑。
  • 模式双向兼容:strict 存储的值受控传入 non-strict 能被 conductCheck 正确消化,反之亦然,切换无脏数据。

Tests

新增 7 个 checkStrictly 用例(tests/checkable.spec.tsx):

  • 父不联动子 / 子不影响父 / 无 indeterminate
  • 非叶子中间值精确受控选中
  • showCheckedStrategy 被忽略
  • missing 值保留与可移除
  • disabled 兄弟节点对照(strict vs non-strict 模式差异锁定)
  • 受控 value round-trip

全量 rc-test:126 passed / 2 skipped。tsc --noEmit 通过。

Docs

  • README API 表格补 checkStrictly 行。
  • 新增 demo examples/multiple-strict.tsx + docs/demo/multiple-strict.md

🤖 Generated with Claude Code

Summary by CodeRabbit

  • 新功能

    • 新增 checkStrictly 属性,支持父子节点独立勾选,适用于多选级联场景。
    • 严格模式下支持精确保留各级选中值,不受选中汇总策略影响。
    • 新增多级独立勾选示例,展示选中结果变化。
  • 文档

    • 完善 Cascader API 属性说明,补充 checkStrictlystylesoptionRender 等内容。
  • 测试

    • 增加严格勾选、受控值、缺失值及禁用节点等场景的验证。

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>
@vercel

vercel Bot commented Aug 18, 2026

Copy link
Copy Markdown

Someone 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 18, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 08f5f6d6-bc77-4d12-be32-874a88e31069

📥 Commits

Reviewing files that changed from the base of the PR and between 9d1fa80 and 31e66b1.

📒 Files selected for processing (8)
  • README.md
  • docs/demo/multiple-strict.md
  • examples/multiple-strict.tsx
  • src/Cascader.tsx
  • src/Panel.tsx
  • src/hooks/useSelect.ts
  • src/hooks/useValues.ts
  • tests/checkable.spec.tsx

Included review availability: Your plan includes up to 2 reviews per rolling hour; 1 remains after this review.


Walkthrough

Cascader 新增 checkStrictly 属性。启用后,父子节点独立选中,不执行级联汇总或半选计算。组件、示例、文档和测试均已更新。

Changes

严格级联选择

Layer / File(s) Summary
API 与组件 wiring
src/Cascader.tsx, src/Panel.tsx
新增 checkStrictly 公共属性。组件将该属性传递给值计算和选择处理逻辑。
严格勾选逻辑
src/hooks/useValues.ts, src/hooks/useSelect.ts
严格模式直接处理路径值。该模式跳过父子级联、半选计算和 showCheckedStrategy 汇总。
示例、文档与行为验证
examples/multiple-strict.tsx, docs/demo/multiple-strict.md, README.md, tests/checkable.spec.tsx
新增严格模式示例和文档。测试覆盖独立勾选、缺失值、禁用节点及受控值行为。

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 31e66

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: 返回独立选中路径
Loading

Poem

我是小兔,轻跳过树梢,
严格勾选让父子分道。
每条路径各自闪耀,
半选状态不再打扰。
测试守护,文档引导,
Cascader 开心蹦跳!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed 实现满足 Issue #38049:在 multiple 模式下启用 checkStrictly 后,父子节点选中状态互不关联。
Out of Scope Changes check ✅ Passed 代码、测试、文档和演示均直接支持 checkStrictly 功能,未发现无关变更。
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了新增 checkStrictly 属性及父子节点独立选中行为这一主要变更。
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.40%. Comparing base (9d1fa80) to head (31e66b1).

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.
📢 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.

@nrps9909 nrps9909 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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/CJS father build outputs: 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.

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