Skip to content

fix(Cascader): preserve normalized option keys - #3501

Open
chengluliu wants to merge 1 commit into
jdf2e:feat_v4.xfrom
chengluliu:fix/cascader-option-key
Open

fix(Cascader): preserve normalized option keys#3501
chengluliu wants to merge 1 commit into
jdf2e:feat_v4.xfrom
chengluliu:fix/cascader-option-key

Conversation

@chengluliu

@chengluliu chengluliu commented Aug 1, 2026

Copy link
Copy Markdown

🤔 这个变动的性质是?

  • 日常 bug 修复
  • 测试用例

🔗 相关 Issue

Closes #3429

💡 需求背景和解决方案

optionKeytextKeyvalueKey 映射到同一原始字段时,others 会在归一化字段之后展开并覆盖 textvalue

调整字段展开顺序,先保留其他属性,再写入归一化后的 textvaluechildren。同时补充两种同字段映射的回归用例。

☑️ 请求合并前的自查清单

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • fork仓库代码是否为最新避免文件冲突
  • Files changed 没有 package.json lock 等无关文件

✅ 验证

  • pnpm test
  • pnpm build
  • pnpm build:taro

Summary by CodeRabbit

  • Bug Fixes
    • 修复级联选择器选项字段规范化问题,确保自定义文本和值字段正确映射。
    • 确保标准化后的字段覆盖原始同名属性,并保留 children: undefined 状态。

@github-actions github-actions Bot added the action:review This PR needs more reviews (less than 2 approvals) label Aug 1, 2026
@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

normalizeOptions 调整对象属性展开顺序,使归一化后的 textvaluechildren 覆盖原始同名属性。测试覆盖自定义字段映射和缺失子节点。

Changes

Cascader 属性归一化

Layer / File(s) Summary
归一化字段覆盖与测试
src/packages/cascader/utils.ts, src/packages/cascader/__tests__/cascader.spec.tsx
normalizeOptions 先展开原始字段,再设置标准化的 textvaluechildren。新增测试验证自定义 textKeyvalueKey、无关字段保留,以及 children: undefined

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

Possibly related PRs

Poem

小兔敲代码,字段排整齐,
textvalue 不再被覆盖。
children 缺席也明确,
测试灯光亮晶晶。
Cascader 轻快地跳起。

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed 标题准确概括了 Cascader 归一化字段覆盖问题的修复。
Description check ✅ Passed 描述包含变更性质、关联 Issue、问题背景、解决方案、自查清单和验证命令。
Linked Issues check ✅ Passed 代码调整字段展开顺序并增加两种回归测试,满足 Issue #3429 的全部编码目标。
Out of Scope Changes check ✅ Passed 变更仅涉及 normalizeOptions 修复及对应测试,未发现与 Issue #3429 无关的内容。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 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.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
src/packages/cascader/__tests__/cascader.spec.tsx (1)

90-108: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

补充真正的无关字段断言。

当前 options 只包含 textvalue。这两个字段都会被归一化字段覆盖,因此断言没有验证 ...others 是否保留无关属性。请加入 disabled 或其他非 text/value 字段,并在两个期望结果中断言该字段仍存在。

建议修改
-    const options = [{ text: '北京', value: '021' }]
+    const options = [{ text: '北京', value: '021', disabled: true }]

同时在两个期望结果中加入:

disabled: true
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/packages/cascader/__tests__/cascader.spec.tsx` around lines 90 - 108,
Update the options fixture in the test “normalizes mapped fields after
preserving unrelated option fields” to include a non-text/value field such as
disabled: true, and add that field to both expected normalized results while
preserving the existing mapped-field assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/packages/cascader/__tests__/cascader.spec.tsx`:
- Around line 90-108: Update the options fixture in the test “normalizes mapped
fields after preserving unrelated option fields” to include a non-text/value
field such as disabled: true, and add that field to both expected normalized
results while preserving the existing mapped-field assertions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e66a43d7-a72b-41f8-8654-d0328faf952c

📥 Commits

Reviewing files that changed from the base of the PR and between 6efc38c and cbc6c96.

📒 Files selected for processing (2)
  • src/packages/cascader/__tests__/cascader.spec.tsx
  • src/packages/cascader/utils.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action:review This PR needs more reviews (less than 2 approvals) size/S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cascader 组件自定义属性名逻辑存在严重Bug

1 participant