From 5d429421b0be10671ce424e4879360b7a645a686 Mon Sep 17 00:00:00 2001 From: devmtnaing Date: Sun, 27 Sep 2026 01:51:39 +0630 Subject: [PATCH] Stepper keys, screen-reader narration and native dark controls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Space on a focused button, link or disclosure presses it instead of toggling playback; Alt/Ctrl/Cmd combos go to the browser (Alt+← is Back). - Approach and language tabs take ←/→/Home/End and use a roving tabindex, so only the selected tab is a Tab stop. - The narration is a polite live region, muted while autoplay runs; the scrubber announces "Step 2 of 12: tally" via aria-valuetext. - tokens.css sets color-scheme per theme, so scrollbars, range tracks and spinners are drawn dark on the dark theme. --- src/lib/stepper.js | 55 ++++++++++++++++++++++++++++++++++++------- src/styles/tokens.css | 7 +++++- 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/src/lib/stepper.js b/src/lib/stepper.js index 35cd81a..82b0066 100644 --- a/src/lib/stepper.js +++ b/src/lib/stepper.js @@ -41,10 +41,33 @@ const $ = (sel, el = document) => el.querySelector(sel); const esc = (s) => String(s ?? '').replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c])); const nameOf = (k) => (typeof k === 'string' ? k : k?.en ?? ''); +/* A tab's selection attributes. Only the selected tab sits in the Tab order; + * the arrow keys move between the rest (tabKeys below). */ +const tabAttrs = (on) => `aria-selected="${on}" tabindex="${on ? 0 : -1}"`; +const selectTabs = (tabs, isOn) => tabs.forEach((b) => { + const on = isOn(b); + b.setAttribute('aria-selected', String(on)); + b.tabIndex = on ? 0 : -1; +}); + +/* Arrow keys, Home and End inside a tablist: move to that tab and select it. */ +function tabKeys(e) { + const tab = e.target.closest('[role="tab"]'); + if (!tab || e.altKey || e.ctrlKey || e.metaKey) return; + const tabs = [...tab.closest('[role="tablist"]').querySelectorAll('[role="tab"]')]; + const i = tabs.indexOf(tab); + const j = { ArrowRight: i + 1, ArrowLeft: i - 1, Home: 0, End: tabs.length - 1 }[e.key]; + if (j == null) return; + e.preventDefault(); + const to = tabs[(j + tabs.length) % tabs.length]; + to.click(); + to.focus(); +} + /* The code-language tabs: `mini` above the live code, plain above part 3. */ const langBar = (langs, active, cls = '') => `
${langs.map((l) => - ``).join('')} + ``).join('')}
`; /* Chrome owned by the engine rather than by any one lesson. */ @@ -58,6 +81,7 @@ const UI = { pause: { en: 'Pause', my: 'ရပ်' }, scrub: { en: 'Scrub through steps', my: 'အဆင့်များကို ဆွဲကြည့်ရန်' }, step: { en: 'step', my: 'အဆင့်' }, + stepOf: { en: 'Step {i} of {n}', my: 'အဆင့် {i} / {n}' }, answer: { en: 'answer', my: 'answer' }, codeLive: { en: 'The code, live', my: 'အလုပ်လုပ်နေသော code' }, input: { en: 'Input', my: 'Input' }, @@ -146,7 +170,7 @@ export function mountLesson(cfg) { ` : ''; const tabs = cfg.modes.map((m) => ` -