refs.ts 534 B

1234567891011121314151617
  1. import { isFunction } from '../types';
  2. import type { ComponentPublicInstance, Ref } from 'vue';
  3. export type RefSetter = (el: Element | ComponentPublicInstance | undefined) => void;
  4. export const composeRefs = (...refs: (Ref<HTMLElement | undefined> | RefSetter)[]) => {
  5. return (el: Element | ComponentPublicInstance | null) => {
  6. refs.forEach((ref) => {
  7. if (isFunction(ref)) {
  8. ref(el as Element | ComponentPublicInstance);
  9. } else {
  10. ref.value = el as HTMLElement | undefined;
  11. }
  12. });
  13. };
  14. };