From 874aa0a2848893e9d3278306c96b6fbe81217b84 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Thu, 27 Oct 2022 21:41:27 +0800 Subject: [PATCH] refactor(components): [select] use util function (#10286) --- packages/components/select/src/useSelect.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/components/select/src/useSelect.ts b/packages/components/select/src/useSelect.ts index 0c972c68eb..f2dea5bd33 100644 --- a/packages/components/select/src/useSelect.ts +++ b/packages/components/select/src/useSelect.ts @@ -22,6 +22,8 @@ import { getComponentSize, isFunction, isKorean, + isNumber, + isString, scrollIntoView, } from '@element-plus/utils' import { @@ -347,7 +349,7 @@ export const useSelect = (props, states: States, ctx) => { watch( () => states.hoverIndex, (val) => { - if (typeof val === 'number' && val > -1) { + if (isNumber(val) && val > -1) { hoverOption.value = optionsArray.value[val] || {} } else { hoverOption.value = {} @@ -393,8 +395,7 @@ export const useSelect = (props, states: States, ctx) => { if (states.previousQuery === val || states.isOnComposition) return if ( states.previousQuery === null && - (typeof props.filterMethod === 'function' || - typeof props.remoteMethod === 'function') + (isFunction(props.filterMethod) || isFunction(props.remoteMethod)) ) { states.previousQuery = val return @@ -412,10 +413,10 @@ export const useSelect = (props, states: States, ctx) => { resetInputHeight() }) } - if (props.remote && typeof props.remoteMethod === 'function') { + if (props.remote && isFunction(props.remoteMethod)) { states.hoverIndex = -1 props.remoteMethod(val) - } else if (typeof props.filterMethod === 'function') { + } else if (isFunction(props.filterMethod)) { props.filterMethod(val) triggerRef(groupQueryChange) } else { @@ -612,7 +613,7 @@ export const useSelect = (props, states: States, ctx) => { const deleteSelected = (event) => { event.stopPropagation() const value: string | any[] = props.multiple ? [] : '' - if (typeof value !== 'string') { + if (!isString(value)) { for (const item of states.selected) { if (item.isDisabled) value.push(item.value) }