refactor(components): use built-in methods to check for undefined and null (#20537)

style(components): check the undefined type for unification
This commit is contained in:
betavs
2025-04-24 22:51:58 +08:00
committed by GitHub
parent 27229ac4fa
commit 3a3db6e564
5 changed files with 9 additions and 6 deletions

View File

@@ -25,6 +25,7 @@ import {
isArray,
isObject,
isString,
isUndefined,
mutable,
} from '@element-plus/utils'
import { useNamespace } from '@element-plus/hooks'
@@ -190,7 +191,7 @@ export const menuEmits = {
isString(index) &&
checkIndexPath(indexPath) &&
isObject(item) &&
(routerResult === undefined || routerResult instanceof Promise),
(isUndefined(routerResult) || routerResult instanceof Promise),
}
export type MenuEmits = typeof menuEmits

View File

@@ -21,6 +21,7 @@ import {
buildProps,
iconPropType,
isString,
isUndefined,
throwError,
} from '@element-plus/utils'
import { useNamespace } from '@element-plus/hooks'
@@ -148,7 +149,7 @@ export default defineComponent({
const isFirstLevel = computed(() => subMenu.level === 0)
const appendToBody = computed(() => {
const value = props.teleported
return value === undefined ? isFirstLevel.value : value
return isUndefined(value) ? isFirstLevel.value : value
})
const menuTransitionName = computed(() =>
rootMenu.props.collapse

View File

@@ -22,6 +22,7 @@ import {
isFunction,
isNumber,
isObject,
isUndefined,
} from '@element-plus/utils'
import {
useComposition,
@@ -686,7 +687,7 @@ const useSelect = (props: ISelectV2Props, emit: SelectEmitFn) => {
if (!expanded.value) {
return toggleMenu()
}
if (hoveringIndex === undefined) {
if (isUndefined(hoveringIndex)) {
hoveringIndex = states.hoveringIndex
}
let newIndex = -1

View File

@@ -75,7 +75,7 @@ const getPropertyFromData = function (node: Node, prop: string): any {
return data[config]
} else if (isUndefined(config)) {
const dataProp = data[prop]
return dataProp === undefined ? '' : dataProp
return isUndefined(dataProp) ? '' : dataProp
}
}
@@ -493,7 +493,7 @@ class Node {
children = props.children || 'children'
}
if (data[children] === undefined) {
if (isUndefined(data[children])) {
data[children] = null
}

View File

@@ -412,7 +412,7 @@ export default class TreeStore {
setCurrentNodeKey(key?: TreeKey, shouldAutoExpandParent = true): void {
this.currentNodeKey = key
if (key === null || key === undefined) {
if (isPropAbsent(key)) {
this.currentNode && (this.currentNode.isCurrent = false)
this.currentNode = null
return