+
@@ -253,6 +277,9 @@ export function mountLesson(cfg) {
const scrub = $('[data-scrub]', root);
scrub.max = String(state.steps.length - 1);
scrub.value = String(state.i);
+ // what a screen reader says for the scrubber: "Step 2 of 12: tally"
+ const where = pick(UI.stepOf).replace('{i}', state.i + 1).replace('{n}', state.steps.length);
+ scrub.setAttribute('aria-valuetext', pick(s.tag) ? `${where}: ${pick(s.tag)}` : where);
$('[data-count]', root).textContent = `${state.i + 1} / ${state.steps.length}`;
}
@@ -287,15 +314,21 @@ export function mountLesson(cfg) {
state.i = Math.max(0, Math.min(state.steps.length - 1, i));
render();
}
+ // The narration is a live region, so a screen reader reads each step the
+ // reader moves to. While playing it goes quiet — a step every 700 ms would
+ // queue up faster than it can be read — and speaks again on stop.
+ const narrate = (on) => $('[data-narration]', root)?.setAttribute('aria-live', on ? 'polite' : 'off');
function stop() {
clearInterval(state.timer);
state.timer = null;
const b = $('[data-act="play"]', root);
if (b) b.textContent = pick(UI.play);
+ narrate(true);
}
function play() {
if (state.i >= state.steps.length - 1) state.i = 0;
$('[data-act="play"]', root).textContent = pick(UI.pause);
+ narrate(false);
state.timer = setInterval(() => {
if (state.i >= state.steps.length - 1) return stop();
go(state.i + 1);
@@ -310,8 +343,7 @@ export function mountLesson(cfg) {
function setLangAll(id) {
state.lang = id;
- document.querySelectorAll('[data-lang]').forEach((b) =>
- b.setAttribute('aria-selected', String(b.dataset.lang === id)));
+ selectTabs(document.querySelectorAll('[data-lang]'), (b) => b.dataset.lang === id);
document.querySelectorAll('[data-pane]').forEach((p) => { p.hidden = p.dataset.pane !== id; });
render();
}
@@ -358,8 +390,7 @@ export function mountLesson(cfg) {
if (card) {
stop();
state.mode = card.dataset.mode;
- root.querySelectorAll('[data-mode]').forEach((b) =>
- b.setAttribute('aria-selected', String(b.dataset.mode === state.mode)));
+ selectTabs(root.querySelectorAll('[data-mode]'), (b) => b.dataset.mode === state.mode);
rebuild();
return;
}
@@ -372,10 +403,15 @@ export function mountLesson(cfg) {
});
// Arrow keys and space — never while someone is typing, and only while the
- // walkthrough is on screen, so a widget elsewhere keeps its own keys.
+ // walkthrough is on screen, so a widget elsewhere keeps its own keys. A
+ // modified key is the browser's (Alt+← is Back), a tab's arrows move between
+ // tabs, and space on a focused control presses that control, not Play.
+ root.addEventListener('keydown', tabKeys);
document.addEventListener('keydown', (e) => {
+ if (e.altKey || e.ctrlKey || e.metaKey) return;
if (e.target.closest('input,textarea,select,[contenteditable]')) return;
- if (e.target.closest('#q-widget')) return;
+ if (e.target.closest('#q-widget, [role="tab"]')) return;
+ if (e.key === ' ' && e.target.closest('button, a[href], summary, [role="button"]')) return;
const r = root.getBoundingClientRect();
if (r.bottom < 0 || r.top > innerHeight) return;
const name = { ArrowRight: 'next', ArrowLeft: 'prev', ' ': 'play' }[e.key];
@@ -538,6 +574,7 @@ function renderSolutions(cfg, activeLang) {
}).join('')}
`).join('')}`;
+ host.onkeydown = tabKeys;
host.onclick = (e) => {
const langBtn = e.target.closest('[data-lang]');
// the live code panel's tab switches every tab and pane on the page
diff --git a/src/styles/tokens.css b/src/styles/tokens.css
index db9f7cd..b3170ab 100644
--- a/src/styles/tokens.css
+++ b/src/styles/tokens.css
@@ -1,8 +1,11 @@
/* Palette and shape, in all three theme states: system, forced light,
forced dark. Every other stylesheet reads colour only through these.
Text colours clear WCAG AA (4.5:1) on every background they sit on —
- ground, surface, sunk and the soft tints; npm run audit checks it. */
+ ground, surface, sunk and the soft tints; npm run audit checks it.
+ color-scheme follows the theme so native parts — scrollbars, range
+ tracks, number spinners — are drawn dark on the dark theme too. */
:root{
+ color-scheme:light;
--ground:#EEF2F2;
--surface:#FFFFFF;
--sunk:#E3E9EA;
@@ -24,6 +27,7 @@
}
@media (prefers-color-scheme: dark){
:root:not([data-theme="light"]){
+ color-scheme:dark;
--ground:#0C1315;
--surface:#141E21;
--sunk:#0F1A1D;
@@ -44,6 +48,7 @@
}
}
:root[data-theme="dark"]{
+ color-scheme:dark;
--ground:#0C1315;
--surface:#141E21;
--sunk:#0F1A1D;