Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Oct 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions packages/components/select/src/useSelect.ts
Expand Up @@ -22,6 +22,8 @@ import {
getComponentSize,
isFunction,
isKorean,
isNumber,
isString,
scrollIntoView,
} from '@element-plus/utils'
import {
Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down