diff --git a/packages/vuetify/src/components/VOverlay/VOverlay.tsx b/packages/vuetify/src/components/VOverlay/VOverlay.tsx index 70cedce4870..14ec2c1fcae 100644 --- a/packages/vuetify/src/components/VOverlay/VOverlay.tsx +++ b/packages/vuetify/src/components/VOverlay/VOverlay.tsx @@ -154,9 +154,13 @@ export const VOverlay = genericComponent()({ contentEvents, scrimEvents, } = useActivator(props, { isActive, isTop: localTop }) - const potentialShadowDomRoot = computed(() => (activatorEl?.value as Element)?.getRootNode() as Element) - const { teleportTarget } = useTeleport(computed(() => props.attach || props.contained || - potentialShadowDomRoot.value instanceof ShadowRoot ? potentialShadowDomRoot.value ?? true : false)) + const { teleportTarget } = useTeleport(() => { + const target = props.attach || props.contained + if (target) return target + const rootNode = activatorEl?.value?.getRootNode() + if (rootNode instanceof ShadowRoot) return rootNode + return false + }) const { dimensionStyles } = useDimension(props) const isMounted = useHydration() const { scopeId } = useScopeId() diff --git a/packages/vuetify/src/composables/teleport.ts b/packages/vuetify/src/composables/teleport.ts index a0fdf7581b7..f90000277a5 100644 --- a/packages/vuetify/src/composables/teleport.ts +++ b/packages/vuetify/src/composables/teleport.ts @@ -2,12 +2,9 @@ import { computed, warn } from 'vue' import { IN_BROWSER } from '@/util' -// Types -import type { Ref } from 'vue' - -export function useTeleport (target: Ref) { +export function useTeleport (target: () => (boolean | string | ParentNode)) { const teleportTarget = computed(() => { - const _target = target.value + const _target = target() if (_target === true || !IN_BROWSER) return undefined