From 1bca12d6aea83d668eb5ddc5db224492965463cd Mon Sep 17 00:00:00 2001 From: Ryan2128 <33176053+Ryan2128@users.noreply.github.com> Date: Sun, 7 Feb 2021 05:11:03 -0600 Subject: [PATCH] fix(select): fix bug cause by scrollToOption (#1440) --- packages/select/src/useSelect.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/select/src/useSelect.ts b/packages/select/src/useSelect.ts index e1a7d07f43..d98c092519 100644 --- a/packages/select/src/useSelect.ts +++ b/packages/select/src/useSelect.ts @@ -520,15 +520,17 @@ export const useSelect = (props, states: States, ctx) => { } } - const getEl = option => { - const options = states.options.filter(item => item.value === option.value) - if (options.length > 0) { - return options[0].$el - } - } - const scrollToOption = option => { - const target = Array.isArray(option) ? getEl(option[0]) : getEl(option) + const targetOption = Array.isArray(option) ? option[0] : option + let target = null + + if(targetOption?.value){ + const options = states.options.filter(item => item.value === targetOption.value) + if (options.length > 0) { + target = options[0].$el + } + } + if (popper.value && target) { const menu = popper.value?.popperRef?.querySelector?.('.el-select-dropdown__wrap') if (menu) {