The guided walk finds its elements in the rendered tree

Template refs are filled after a render returns, and later still when the
walk starts inside one of Vue's own post-render updates, where the walk
would have failed with its listeners already in place.

Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
Sameh KhamisandManjunath Paparaju committed 2026-11-19 02:16:38 -08:00
1 parent 10a26e15ce
commit 4a6f185d07
3 files changed
+35 -15

No files matched your search

+7 -5
View File
@@ -501,14 +501,16 @@ export function startGuide(steps, { title = '' } = {}) {
...handlers,
});
renderVue(vnode, host);
return vnode.component.exposed;
return vnode;
}
// Focus returns where it was when the walk ends, if that is still there.
const returnFocus = doc.activeElement;
const elements = paint();
const root = elements.root.value;
const ring = elements.ring.value;
const callout = elements.callout.value;
// The elements come from the rendered tree, which is in place as soon as the
// render returns; template refs are filled after it, and later still when
// the walk starts inside one of Vue's own post-render updates.
const root = paint().component.subTree.children[0].el;
const ring = root.querySelector(':scope > .gev-guide-ring');
const callout = root.querySelector(':scope > .gev-guide-callout');
const subRings = [];
const live = steps.filter(Boolean);
+25
View File
@@ -2,6 +2,7 @@
import '../testSupport/registerDom.mjs';
import test from 'node:test';
import assert from 'node:assert/strict';
import { createApp, h, onMounted } from 'vue';
import { startGuide } from './omnibarGuide.js';
const settle = () => new Promise((resolve) => setTimeout(resolve, 0));
@@ -109,3 +110,27 @@ test('starting another walk ends the one in progress', async (t) => {
assert.equal(document.querySelectorAll('.gev-guide').length, 1);
assert.equal($('.gev-guide-text').textContent, 'Second');
});
test('a walk started while Vue mounts something else still starts and ends', async (t) => {
const { target, field } = fixture(t);
let stop = null;
const app = createApp({
setup() {
onMounted(() => {
stop = startGuide([
{ targets: () => [target], text: () => 'Press it' },
]);
});
return () => h('span');
},
});
app.mount(document.body.appendChild(document.createElement('div')));
t.after(() => app.unmount());
await settle();
assert.equal(typeof stop, 'function');
assert.equal(document.activeElement, $('.gev-guide-callout'));
assert.ok($('.gev-guide').classList.contains('visible'));
stop();
assert.equal($('.gev-guide'), null);
assert.equal(document.activeElement, field);
});
+3 -10
View File
@@ -1,5 +1,4 @@
<script setup>
import { ref } from 'vue';
import UiButton from '../../kit/UiButton.vue';
import UiCloseButton from '../../kit/UiCloseButton.vue';
@@ -9,7 +8,7 @@ import UiCloseButton from '../../kit/UiCloseButton.vue';
// with the `view` it computes for each step and keeps the parts the template
// never binds: the guide's `visible` class, the callout's entrance replay
// (its `swap` class), place and side, the ring's and the extra rings' boxes,
// and focus. The elements those parts need are exposed.
// and focus. It finds those elements in the rendered tree itself.
defineProps({
to: { type: Object, required: true },
view: { type: Object, required: true },
@@ -19,21 +18,15 @@ defineProps({
onNext: { type: Function, required: true },
});
const root = ref(null);
const ring = ref(null);
const callout = ref(null);
defineExpose({ root, ring, callout });
/** A progress segment's attributes: no class at all for one still to come. */
const dot = (name) => (name ? { class: name } : {});
</script>
<!-- Only line breaks inside tags: the markup has no whitespace between elements. -->
<template><Teleport :to="to"
><div ref="root" class="gev-guide"
><div ref="ring" class="gev-guide-ring"><i></i></div
><div class="gev-guide"
><div class="gev-guide-ring"><i></i></div
><div
ref="callout"
class="gev-guide-callout"
role="dialog"
aria-modal="false"