2022-03-26 13:33:24 +08:00
|
|
|
import { isFunction } from '@element-plus/utils'
|
|
|
|
|
2022-02-11 11:03:15 +08:00
|
|
|
import type { ComponentPublicInstance, Ref } from 'vue'
|
|
|
|
|
2022-03-26 13:33:24 +08:00
|
|
|
export type RefSetter = (
|
|
|
|
el: Element | ComponentPublicInstance | undefined
|
|
|
|
) => void
|
|
|
|
|
|
|
|
export const composeRefs = (
|
|
|
|
...refs: (Ref<HTMLElement | undefined> | RefSetter)[]
|
|
|
|
) => {
|
2022-02-11 11:03:15 +08:00
|
|
|
return (el: Element | ComponentPublicInstance | null) => {
|
|
|
|
refs.forEach((ref) => {
|
2022-03-26 13:33:24 +08:00
|
|
|
if (isFunction(ref)) {
|
|
|
|
ref(el as Element | ComponentPublicInstance)
|
|
|
|
} else {
|
|
|
|
ref.value = el as HTMLElement | undefined
|
|
|
|
}
|
2022-02-11 11:03:15 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|