Commit 8857d163b36d171dc9759788718c8ba42f23c85c
Committed by
GitHub
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 | 560 | if (e.key === 'Enter') { |
| 561 | 561 | if (this.focusIndex === -1) return this.hideMenu(); |
| 562 | 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 | 572 | } else { |
| 567 | 573 | const keysThatCanOpenSelect = ['ArrowUp', 'ArrowDown']; |
| ... | ... | @@ -765,7 +771,7 @@ |
| 765 | 771 | if (this.slotOptions && this.slotOptions.length === 0){ |
| 766 | 772 | this.query = ''; |
| 767 | 773 | } |
| 768 | - | |
| 774 | + | |
| 769 | 775 | // 当 dropdown 一开始在控件下部显示,而滚动页面后变成在上部显示,如果选项列表的长度由内部动态变更了(搜索情况) |
| 770 | 776 | // dropdown 的位置不会重新计算,需要重新计算 |
| 771 | 777 | this.broadcast('Drop', 'on-update-popper'); | ... | ... |