Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(teleport/css-v-bind): support for getting teleported content via target #12299

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/runtime-core/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ export interface ComponentInternalInstance {
* For updating css vars on contained teleports
* @internal
*/
ut?: (vars?: Record<string, string>) => void
ut?: (target: RendererElement | null, vars?: Record<string, string>) => void

/**
* dev only. For style v-bind hydration mismatch checks
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/components/Teleport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ function updateCssVars(vnode: VNode, isDisabled: boolean) {
if (node.nodeType === 1) node.setAttribute('data-v-owner', ctx.uid)
node = node.nextSibling
}
ctx.ut()
ctx.ut(vnode.target)
}
}

Expand Down
11 changes: 8 additions & 3 deletions packages/runtime-dom/src/helpers/useCssVars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ export function useCssVars(getter: (ctx: any) => Record<string, string>): void {
}
/* v8 ignore stop */

const updateTeleports = (instance.ut = (vars = getter(instance.proxy)) => {
const updateTeleports = (instance.ut = (
target,
vars = getter(instance.proxy),
) => {
Array.from(
document.querySelectorAll(`[data-v-owner="${instance.uid}"]`),
((target as Element) || document).querySelectorAll(
`[data-v-owner="${instance.uid}"]`,
),
).forEach(node => setVarsOnNode(node, vars))
})

Expand All @@ -45,7 +50,7 @@ export function useCssVars(getter: (ctx: any) => Record<string, string>): void {
} else {
setVarsOnVNode(instance.subTree, vars)
}
updateTeleports(vars)
updateTeleports(document, vars)
}

onBeforeMount(() => {
Expand Down