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, getComponentSize,
isFunction, isFunction,
isKorean, isKorean,
isNumber,
isString,
scrollIntoView, scrollIntoView,
} from '@element-plus/utils' } from '@element-plus/utils'
import { import {
@ -347,7 +349,7 @@ export const useSelect = (props, states: States, ctx) => {
watch( watch(
() => states.hoverIndex, () => states.hoverIndex,
(val) => { (val) => {
if (typeof val === 'number' && val > -1) { if (isNumber(val) && val > -1) {
hoverOption.value = optionsArray.value[val] || {} hoverOption.value = optionsArray.value[val] || {}
} else { } else {
hoverOption.value = {} hoverOption.value = {}
@ -393,8 +395,7 @@ export const useSelect = (props, states: States, ctx) => {
if (states.previousQuery === val || states.isOnComposition) return if (states.previousQuery === val || states.isOnComposition) return
if ( if (
states.previousQuery === null && states.previousQuery === null &&
(typeof props.filterMethod === 'function' || (isFunction(props.filterMethod) || isFunction(props.remoteMethod))
typeof props.remoteMethod === 'function')
) { ) {
states.previousQuery = val states.previousQuery = val
return return
@ -412,10 +413,10 @@ export const useSelect = (props, states: States, ctx) => {
resetInputHeight() resetInputHeight()
}) })
} }
if (props.remote && typeof props.remoteMethod === 'function') { if (props.remote && isFunction(props.remoteMethod)) {
states.hoverIndex = -1 states.hoverIndex = -1
props.remoteMethod(val) props.remoteMethod(val)
} else if (typeof props.filterMethod === 'function') { } else if (isFunction(props.filterMethod)) {
props.filterMethod(val) props.filterMethod(val)
triggerRef(groupQueryChange) triggerRef(groupQueryChange)
} else { } else {
@ -612,7 +613,7 @@ export const useSelect = (props, states: States, ctx) => {
const deleteSelected = (event) => { const deleteSelected = (event) => {
event.stopPropagation() event.stopPropagation()
const value: string | any[] = props.multiple ? [] : '' const value: string | any[] = props.multiple ? [] : ''
if (typeof value !== 'string') { if (!isString(value)) {
for (const item of states.selected) { for (const item of states.selected) {
if (item.isDisabled) value.push(item.value) if (item.isDisabled) value.push(item.value)
} }