Skip to content
This repository was archived by the owner on Sep 28, 2022. It is now read-only.

Commit d24df5e

Browse files
cs1707CarterLi
authored andcommitted
Cascader: fix emitPath (ElemeFE#21185)
1 parent 6bbd481 commit d24df5e

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

packages/cascader-panel/src/cascader-panel.vue

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export default {
157157
},
158158
159159
mounted() {
160-
if (!isEmpty(this.value)) {
160+
if (!this.isEmptyValue(this.value)) {
161161
this.syncCheckedValue();
162162
}
163163
},
@@ -195,13 +195,21 @@ export default {
195195
node.syncCheckState(this.checkedValue);
196196
});
197197
},
198+
isEmptyValue(val) {
199+
const { multiple, config } = this;
200+
const { emitPath } = config;
201+
if (multiple || emitPath) {
202+
return isEmpty(val);
203+
}
204+
return false;
205+
},
198206
syncActivePath() {
199207
const { store, multiple, activePath, checkedValue } = this;
200208
201209
if (!isEmpty(activePath)) {
202210
const nodes = activePath.map(node => this.getNodeByValue(node.getValue()));
203211
this.expandNodes(nodes);
204-
} else if (!isEmpty(checkedValue)) {
212+
} else if (!this.isEmptyValue(checkedValue)) {
205213
const value = multiple ? checkedValue[0] : checkedValue;
206214
const checkedNode = this.getNodeByValue(value) || {};
207215
const nodes = (checkedNode.pathNodes || []).slice(0, -1);
@@ -363,7 +371,7 @@ export default {
363371
const nodes = this.getFlattedNodes(leafOnly);
364372
return nodes.filter(node => node.checked);
365373
} else {
366-
return isEmpty(checkedValue)
374+
return this.isEmptyValue(checkedValue)
367375
? []
368376
: [this.getNodeByValue(checkedValue)];
369377
}

packages/cascader-panel/src/store.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,8 @@ export default class Store {
5151
}
5252

5353
getNodeByValue(value) {
54-
if (value) {
55-
const nodes = this.getFlattedNodes(false, !this.config.lazy)
56-
.filter(node => (valueEquals(node.path, value) || node.value === value));
57-
return nodes && nodes.length ? nodes[0] : null;
58-
}
59-
return null;
54+
const nodes = this.getFlattedNodes(false, !this.config.lazy)
55+
.filter(node => (valueEquals(node.path, value) || node.value === value));
56+
return nodes && nodes.length ? nodes[0] : null;
6057
}
61-
6258
}

packages/cascader/src/cascader.vue

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ export default {
217217
data() {
218218
return {
219219
dropDownVisible: false,
220-
checkedValue: this.value || null,
220+
checkedValue: this.value,
221221
inputHover: false,
222222
inputValue: null,
223223
presentText: null,
@@ -336,7 +336,7 @@ export default {
336336
this.inputInitialHeight = input.$el.offsetHeight || InputSizeMap[this.realSize] || 40;
337337
}
338338
339-
if (!isEmpty(this.value)) {
339+
if (!this.isEmptyValue(this.value)) {
340340
this.computePresentContent();
341341
}
342342
@@ -471,9 +471,17 @@ export default {
471471
}
472472
});
473473
},
474+
isEmptyValue(val) {
475+
const { multiple } = this;
476+
const { emitPath } = this.panel.config;
477+
if (multiple || emitPath) {
478+
return isEmpty(val);
479+
}
480+
return false;
481+
},
474482
computePresentText() {
475483
const { checkedValue, config } = this;
476-
if (!isEmpty(checkedValue)) {
484+
if (!this.isEmptyValue(checkedValue)) {
477485
const node = this.panel.getNodeByValue(checkedValue);
478486
if (node && (config.checkStrictly || node.isLeaf)) {
479487
this.presentText = node.getText(this.showAllLevels, this.separator);

0 commit comments

Comments
 (0)