Skip to content

Fix/checkbox tree slected error#3898

Merged
fangsmile merged 3 commits into
VisActor:feat/parent_child_selected_syncfrom
ztygod:fix/checkbox_tree_slected_error
May 19, 2025
Merged

Fix/checkbox tree slected error#3898
fangsmile merged 3 commits into
VisActor:feat/parent_child_selected_syncfrom
ztygod:fix/checkbox_tree_slected_error

Conversation

@ztygod
Copy link
Copy Markdown
Contributor

@ztygod ztygod commented May 17, 2025

[中文版模板 / Chinese template]

🤔 This is a ...

  • New feature
  • Bug fix
  • TypeScript definition update
  • Bundle size optimization
  • Performance optimization
  • Enhancement feature
  • Refactoring
  • Update dependency
  • Code style optimization
  • Test Case
  • Branch merge
  • Site / documentation update
  • Demo update
  • Workflow
  • Chore
  • Release
  • Other (about what?)

🔗 Related issue link

[Bug] 当存在checkbox与树形展示的时候,一个子元素(不是叶子元素)的勾选导致另一组的父元素被勾选 #3891

💡 Background and solution

Backgroud

  1. 本地启动
  2. 选择list-tree-checkbox或者list-checkbox-tree。
  3. 勾选“器具”,务必保持“器具”处于折叠状态
  4. 点击“器具”,使其展开
  5. 可以发现,不属于同一组的“技术”也同样被勾选

solution
\packages\vtable\src\event\self-event-listener\list-table\checkbox.ts
原代码 268行

stateArr.forEach((state, i) => {
    const index = keys[i] as string;
    const value = state;

    if (start) {
      const indexData = index.split(',');
      if (indexData.length === currentIndexLength) {
        start = false;
      } else {
        value[field] = parentState;
      }
    }
    if (index === key) {
      start = true;
    }
  });

修改判断逻辑

 // 当前元素的子元素数组
  const childrenOfKey = (keys as string[]).filter(item => item.startsWith(key + ',') && item !== key);

stateArr.forEach((state, i) => {
    const index = keys[i] as string;
    const value = state;
    const shouldSelectChildren = childrenOfKey.length !== 0 && childrenOfKey.includes(index);

    if (start) {
      if (!shouldSelectChildren) {
        start = false;
      } else {
        value[field] = parentState;
      }
    }
    if (index === key) {
      start = true;
    }
  });

📝 Changelog

Language Changelog
🇺🇸 English Modify the judgment logic of whether to check
🇨🇳 Chinese 修改是否勾选的判断逻辑

☑️ Self-Check before Merge

⚠️ Please check all items below before requesting a reviewing. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

🚀 Summary

copilot:summary

🔍 Walkthrough

copilot:walkthrough

@fangsmile fangsmile changed the base branch from develop to feat/parent_child_selected_sync May 19, 2025 03:09
@fangsmile fangsmile merged commit 3f346d2 into VisActor:feat/parent_child_selected_sync May 19, 2025
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants