Skip to content

fix(tree-select): After deleting the last child node of the parent node, another child node is selected. #3508 #3586 #3942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions components/vc-tree-select/src/Select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -874,12 +874,42 @@ const Select = defineComponent({
},

onSearchInputKeyDown(event) {
const { _searchValue: searchValue, _valueList: valueList } = this.$data;
const { _searchValue: searchValue, _valueList: valueList, _valueEntities: valueEntities } = this.$data;

const { keyCode } = event;

if (KeyCode.BACKSPACE === keyCode && this.isMultiple() && !searchValue && valueList.length) {
const lastValue = valueList[valueList.length - 1].value;
// cache result
Copy link
Member

Choose a reason for hiding this comment

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

1、treeCheckStrictly 时不应该处理了

Copy link
Member

Choose a reason for hiding this comment

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

所以不用遍历那么多了,只需要保证 parent 在已选节点中,就代表子节点必然是已选的,
所以也不需要判断 是否disable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已修复,多谢指教 #4047

let tempMap = new WeakMap();
// if childrens‘s status is select all, then remove parent
let lastValue = valueList[valueList.length - 1].value;
const lastValueParent = valueEntities[lastValue].parent;
//every children include node's value or node's disabled is true
function dfs (children) {
if(tempMap.get(children)) return true;
for(let i = 0; i < children.length; i++){
const item = children[i];
if(item.children && item.children.length) {
if(!dfs(item.children)){
return false;
}
}
if(!valueList.some( j => j.value === item.value || item.disabled === true)) {
return false;
}
}
tempMap.set(children, true);
return true;
}
const isAllChoise = lastValueParent && dfs(lastValueParent.children);
if (isAllChoise) {
let cur = lastValueParent.parent;
lastValue = lastValueParent.value;
while(cur) {
dfs(cur.children) && (lastValue = cur.value);
cur = cur.parent;
}
}
this.onMultipleSelectorRemove(event, lastValue);
}
},
Expand Down
6 changes: 4 additions & 2 deletions components/vc-tree/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export function traverseTreeNodes(treeNodes, callback) {
function processNode(node, index, parent) {
const children = node ? getSlot(node) : treeNodes;
const pos = node ? getPosition(parent.pos, index) : 0;
const disabled = node ? node.props.disabled : false

// Filter children
const childList = getNodeChildren(children);
Expand All @@ -71,6 +72,7 @@ export function traverseTreeNodes(treeNodes, callback) {
index,
pos,
key,
disabled,
parentPos: parent.node ? parent.pos : null,
};
callback(data);
Expand Down Expand Up @@ -194,8 +196,8 @@ export function convertTreeToEntities(
}

traverseTreeNodes(treeNodes, item => {
const { node, index, pos, key, parentPos } = item;
const entity = { node, index, key, pos };
const { node, index, pos, key, parentPos, disabled } = item;
const entity = { node, index, key, pos, disabled };

posEntities.set(pos, entity);
keyEntities.set(key, entity);
Expand Down