Vue: the Omnibar's guided walk is a single-file component

OmnibarGuide renders the walk's spotlight ring and callout, teleported to the
end of the body as before, with the kit's UiCloseButton for its close and
UiButtons for Not now, the offer and Next. startGuide() keeps its signature
and every decision and word: it renders the view synchronously from what it
computes for each step and keeps the parts the template never binds: the
guide's visible class and the callout's entrance replay (in the same order,
so the first step still fades in), the callout's place and side and the
rings' boxes each frame, focus and its return, Escape and the checks for a
screen another surface owns.

The ids, roles, aria attributes, hidden attributes, tabindex, text and focus
order are unchanged. The buttons gain the kit's classes, which carry no
rules, so they look as before. The close drops the aria-hidden span around
its glyph: its name is still its aria-label, "End guide", and its tip the
same words. Progress segments are new elements each step, as before, so a
segment's colour does not animate across steps, and the status line changes
once per step.

New tests: the walk is the last of the body, takes focus and gives it back,
announces each step once and draws new progress each step, and a new walk
ends the one in progress.

Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
Sameh KhamisandManjunath Paparaju committed 2026-11-19 02:10:49 -08:00
1 parent 7c858d96ee
commit 10a26e15ce
7 files changed
+293 -80

No files matched your search

+111
View File
@@ -0,0 +1,111 @@
// The guided walk's callout, rendered by startGuide() over happy-dom.
import '../testSupport/registerDom.mjs';
import test from 'node:test';
import assert from 'node:assert/strict';
import { startGuide } from './omnibarGuide.js';
const settle = () => new Promise((resolve) => setTimeout(resolve, 0));
const $ = (selector) => document.querySelector(selector);
function fixture(t) {
document.body.replaceChildren();
const target = document.body.appendChild(document.createElement('button'));
const field = document.body.appendChild(document.createElement('input'));
field.focus();
t.after(() => $('.gev-guide-close')?.click());
return { target, field };
}
test('the walk is the last of the body, takes focus and gives it back', async (t) => {
const { target, field } = fixture(t);
startGuide([{ targets: () => [target], text: () => 'Press it' }], {
title: 'Flights',
});
await settle();
const guide = $('.gev-guide');
assert.equal(document.body.lastElementChild, guide);
assert.equal(guide.parentElement, document.body);
assert.ok(guide.classList.contains('visible'));
const callout = $('.gev-guide-callout');
assert.equal(document.activeElement, callout);
assert.equal(callout.getAttribute('role'), 'dialog');
assert.equal(callout.getAttribute('aria-modal'), 'false');
assert.equal(callout.getAttribute('tabindex'), '-1');
assert.equal($('.gev-guide-title').textContent, 'Guide · Flights');
const close = $('.gev-guide-close');
assert.equal(close.getAttribute('type'), 'button');
assert.equal(close.getAttribute('aria-label'), 'End guide');
assert.equal(close.getAttribute('title'), 'End guide');
assert.ok(close.classList.contains('ui-close-button'));
close.focus();
close.click();
assert.equal($('.gev-guide'), null);
assert.equal(document.activeElement, field);
});
test('the status line says each step once, and each step draws new progress', async (t) => {
const { target } = fixture(t);
startGuide([
{ targets: () => [target], text: () => 'Press it' },
{ text: () => 'Then this' },
{
text: () => 'More?',
offer: { label: () => 'Show more', steps: () => [] },
},
]);
const status = $('.gev-guide-status');
const said = [];
// One change per step: its text replaced once, never cleared first.
const observer = new MutationObserver(() => said.push(status.textContent));
observer.observe(status, {
childList: true,
characterData: true,
subtree: true,
});
t.after(() => observer.disconnect());
await settle();
const firstDots = [...document.querySelectorAll('.gev-guide-progress li')];
assert.deepEqual(
firstDots.map((dot) => dot.getAttribute('class')),
['current', null, null],
);
const next = $('.gev-guide-next');
assert.equal(next.textContent, 'Skip step');
assert.ok(next.classList.contains('quiet'));
assert.equal($('.gev-guide-hint').hidden, false);
next.click();
await settle();
const secondDots = [...document.querySelectorAll('.gev-guide-progress li')];
assert.deepEqual(
secondDots.map((dot) => dot.getAttribute('class')),
['done', 'current', null],
);
assert.ok(secondDots.every((dot) => !firstDots.includes(dot)));
assert.equal(next.textContent, 'Next');
assert.equal(next.classList.contains('quiet'), false);
assert.equal($('.gev-guide-hint').hidden, true);
next.click();
await settle();
// The closing offer: its two buttons, no Esc hint and no Next.
assert.equal($('.gev-guide-keys').hidden, true);
assert.equal(next.hidden, true);
assert.equal($('.gev-guide-skip').hidden, false);
assert.equal($('.gev-guide-skip').textContent, 'Not now');
assert.equal($('.gev-guide-offer').textContent, 'Show more');
assert.deepEqual(said, [
'1 / 3: Press it',
'2 / 3: Then this',
'3 / 3: More?',
]);
$('.gev-guide-skip').click();
assert.equal($('.gev-guide'), null);
});
test('starting another walk ends the one in progress', async (t) => {
fixture(t);
startGuide([{ text: () => 'First' }]);
startGuide([{ text: () => 'Second' }]);
await settle();
assert.equal(document.querySelectorAll('.gev-guide').length, 1);
assert.equal($('.gev-guide-text').textContent, 'Second');
});