Commit 8857d163b36d171dc9759788718c8ba42f23c85c

Authored by Aresn
Committed by GitHub
2 parents 68335adb c87d7efb

Merge pull request #5116 from RookieZoe/2.select

[select] fix script error when searching in select component
Showing 1 changed file with 9 additions and 3 deletions   Show diff stats
src/components/select/select.vue
@@ -560,8 +560,14 @@ @@ -560,8 +560,14 @@
560 if (e.key === 'Enter') { 560 if (e.key === 'Enter') {
561 if (this.focusIndex === -1) return this.hideMenu(); 561 if (this.focusIndex === -1) return this.hideMenu();
562 const optionComponent = this.flatOptions[this.focusIndex]; 562 const optionComponent = this.flatOptions[this.focusIndex];
563 - const option = this.getOptionData(optionComponent.componentOptions.propsData.value);  
564 - this.onOptionClick(option); 563 +
  564 + // fix a script error when searching
  565 + if (optionComponent) {
  566 + const option = this.getOptionData(optionComponent.componentOptions.propsData.value);
  567 + this.onOptionClick(option);
  568 + } else {
  569 + this.hideMenu();
  570 + }
565 } 571 }
566 } else { 572 } else {
567 const keysThatCanOpenSelect = ['ArrowUp', 'ArrowDown']; 573 const keysThatCanOpenSelect = ['ArrowUp', 'ArrowDown'];
@@ -765,7 +771,7 @@ @@ -765,7 +771,7 @@
765 if (this.slotOptions && this.slotOptions.length === 0){ 771 if (this.slotOptions && this.slotOptions.length === 0){
766 this.query = ''; 772 this.query = '';
767 } 773 }
768 - 774 +
769 // 当 dropdown 一开始在控件下部显示,而滚动页面后变成在上部显示,如果选项列表的长度由内部动态变更了(搜索情况) 775 // 当 dropdown 一开始在控件下部显示,而滚动页面后变成在上部显示,如果选项列表的长度由内部动态变更了(搜索情况)
770 // dropdown 的位置不会重新计算,需要重新计算 776 // dropdown 的位置不会重新计算,需要重新计算
771 this.broadcast('Drop', 'on-update-popper'); 777 this.broadcast('Drop', 'on-update-popper');