toElement
Resolves various element reference types to a plain DOM Element. Accepts refs, getters, raw DOM elements, or Vue component instances and normalizes them to a single Element | undefined.
Usage
import { toElement } from '@vuetify/v0'
import { useTemplateRef } from 'vue'
const el = useTemplateRef<HTMLDivElement>('target')
const element = toElement(el) // HTMLDivElement | undefinedArchitecture
toElement resolves multiple input shapes to a DOM element:
Reactivity
toElement is a pure transformer function. It does not track reactivity or return reactive values.
Use inside computed for reactivity Wrap in computed() if you need reactive element resolution:
const resolved = computed(() => toElement(targetRef))Supported Input Types
| Input | Result |
|---|---|
Ref<HTMLElement> | Unwrapped element |
ShallowRef<Element> | Unwrapped element |
() => HTMLElement | Called, returns element |
HTMLElement / SVGElement | Pass-through |
ComponentPublicInstance | Extracts $el |
null / undefined | Returns undefined |
Structural typing Uses { readonly value: T } instead of Vue’s nominal Ref<T> to avoid type mismatches across Vue versions.
Functions
toElement
(target: MaybeElementRef) => Element | undefinedResolves a {@link MaybeElementRef} to a DOM Element or undefined. Handles: - `Ref<Element>`, `ShallowRef<HTMLElement>`, getter functions - Vue component instances (extracts `$el`) - Raw DOM elements (pass-through) - null/undefined (returns undefined)