refactor(components): [select] use util function (#10286)

This commit is contained in:
btea 2022-10-27 21:41:27 +08:00 committed by GitHub
parent c5aa563bc7
commit 874aa0a284
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)
}