Skip to content

Commit d269a0f

Browse files
author
zhiyang
committed
Cascader: not focus when outside clicked
1 parent e58cffa commit d269a0f

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

packages/cascader/src/main.vue

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<template v-if="showAllLevels">
4949
<template v-for="(label, index) in currentLabels">
5050
{{ label }}
51-
<span v-if="index < currentLabels.length - 1"> {{ separator }} </span>
51+
<span v-if="index < currentLabels.length - 1" :key="index"> {{ separator }} </span>
5252
</template>
5353
</template>
5454
<template v-else>
@@ -178,7 +178,9 @@ export default {
178178
menuVisible: false,
179179
inputHover: false,
180180
inputValue: '',
181-
flatOptions: null
181+
flatOptions: null,
182+
id: generateId(),
183+
needFocus: true
182184
};
183185
},
184186
@@ -215,9 +217,6 @@ export default {
215217
},
216218
cascaderDisabled() {
217219
return this.disabled || (this.elForm || {}).disabled;
218-
},
219-
id() {
220-
return generateId();
221220
}
222221
},
223222
@@ -280,7 +279,11 @@ export default {
280279
hideMenu() {
281280
this.inputValue = '';
282281
this.menu.visible = false;
283-
this.$refs.input.focus();
282+
if (this.needFocus) {
283+
this.$refs.input.focus();
284+
} else {
285+
this.needFocus = true;
286+
}
284287
},
285288
handleActiveItemChange(value) {
286289
this.$nextTick(_ => {
@@ -387,6 +390,9 @@ export default {
387390
this.handlePick([], true);
388391
},
389392
handleClickoutside() {
393+
if (this.menuVisible) {
394+
this.needFocus = false;
395+
}
390396
this.menuVisible = false;
391397
},
392398
handleClick() {

packages/cascader/src/menu.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
changeOnSelect: false,
4343
popperClass: '',
4444
hoverTimer: 0,
45-
clicking: false
45+
clicking: false,
46+
id: generateId()
4647
};
4748
},
4849
@@ -97,9 +98,6 @@
9798
formatOptions(optionsCopy);
9899
return loadActiveOptions(optionsCopy);
99100
}
100-
},
101-
id() {
102-
return generateId();
103101
}
104102
},
105103

packages/dropdown/src/dropdown.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,14 @@
6666
menuItems: null,
6767
menuItemsArray: null,
6868
dropdownElm: null,
69-
focusing: false
69+
focusing: false,
70+
listId: `dropdown-menu-${generateId()}`
7071
};
7172
},
7273
7374
computed: {
7475
dropdownSize() {
7576
return this.size || (this.$ELEMENT || {}).size;
76-
},
77-
listId() {
78-
return `dropdown-menu-${generateId()}`;
7977
}
8078
},
8179

0 commit comments

Comments
 (0)