diff --git a/components/vc-tree-select/src/Select.jsx b/components/vc-tree-select/src/Select.jsx index 33edb0edba..e33eaead32 100644 --- a/components/vc-tree-select/src/Select.jsx +++ b/components/vc-tree-select/src/Select.jsx @@ -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 + 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); } }, diff --git a/components/vc-tree/src/util.js b/components/vc-tree/src/util.js index ed5a5e3073..7a905cec32 100644 --- a/components/vc-tree/src/util.js +++ b/components/vc-tree/src/util.js @@ -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); @@ -71,6 +72,7 @@ export function traverseTreeNodes(treeNodes, callback) { index, pos, key, + disabled, parentPos: parent.node ? parent.pos : null, }; callback(data); @@ -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);