From 5917df205c14860a2bd91ed50f7a68ac0d70ba69 Mon Sep 17 00:00:00 2001 From: chencc Date: Sun, 9 May 2021 20:47:52 +0800 Subject: [PATCH] fix(tree-select): After deleting the last child node of the parent node, another child node is selected. #3508 #3586 (#4047) --- components/vc-tree-select/src/Select.jsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/components/vc-tree-select/src/Select.jsx b/components/vc-tree-select/src/Select.jsx index 33edb0edb..e243dd59b 100644 --- a/components/vc-tree-select/src/Select.jsx +++ b/components/vc-tree-select/src/Select.jsx @@ -874,12 +874,24 @@ 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; + let lastValue = valueList[valueList.length - 1].value; + const { treeCheckStrictly } = this.$props; + if(!treeCheckStrictly) { + let cur = valueEntities[lastValue]; + while(cur) { + if(valueList.some(j => j.value === cur.value)) { + lastValue = cur.value; + cur = cur.parent; + }else{ + cur = null + } + } + } this.onMultipleSelectorRemove(event, lastValue); } },