diff --git a/scripts/check-editor-browser.py b/scripts/check-editor-browser.py
index 9e94374..cb48b1f 100644
--- a/scripts/check-editor-browser.py
+++ b/scripts/check-editor-browser.py
@@ -50,6 +50,34 @@
const response = await send('Runtime.evaluate', {expression: '({status: document.querySelector("#checks")?.dataset.result, text: document.querySelector("#checks")?.textContent})', returnByValue: true});
result = response.result.value;
} while ((!result?.status || result.status === 'running') && Date.now() < deadline);
+ if (result?.status === 'passed' && new URL(url).searchParams.has('layout')) {
+ // Check computed accessible names, not title attributes or textContent:
+ // display:none labels and accidental aria-label overrides must fail too.
+ const {root} = await send('DOM.getDocument');
+ const kind = new URL(url).searchParams.get('layout');
+ const names = kind === 'index' ? [] : [
+ ['reset-btn', /^Reset$/], ['format-btn', /^Format$/],
+ ...(kind === 'exercise' ? [['vscode-btn', /^Open in Web Editor$/], ['copy-btn', /^Copy code$/]] : []),
+ ];
+ names.push(['run-btn', /\bRun\b/]);
+ if (kind === 'exercise') names.push(['submit-btn', /\bSubmit(?:ted)?\b/]);
+ try {
+ for (const [role, expected] of names) {
+ const {nodeId} = await send('DOM.querySelector', {nodeId: root.nodeId, selector: `.exercise-section [data-role="${role}"]`});
+ if (!nodeId) throw new Error(`Missing accessible control: ${role}`);
+ const {nodes} = await send('Accessibility.getPartialAXTree', {nodeId, fetchRelatives: false});
+ const control = nodes[0];
+ // Submit is intentionally hidden again after a later source revision.
+ if (role === 'submit-btn' && control?.ignored) continue;
+ if (!control || control.ignored || !expected.test(control.name?.value || '')) {
+ throw new Error(`${role}: expected accessible name ${expected}, got ${JSON.stringify(control)}`);
+ }
+ }
+ result.text += '\nProduction toolbar accessible names verified in Chrome accessibility tree.';
+ } catch (error) {
+ result = {status: 'failed', text: result.text + '\nFAILED: ' + error.message};
+ }
+ }
if (screenshot) {
const image = await send('Page.captureScreenshot');
await writeFile(screenshot, Buffer.from(image.data, 'base64'));
@@ -183,7 +211,7 @@ def main():
cases.append(("workflow", "", (1440, 1400), args.screenshot))
if args.suite != "workflow":
for template in [args.template] if args.template else ["exercise", "playground", "tour", "index"]:
- for width, height in [(375, 500), (800, 450), (1440, 900)]:
+ for width, height in [(320, 500), (375, 500), (800, 450), (1440, 900)]:
name = f"{template}-{width}x{height}"
screenshot = args.screenshot_dir / f"{name}.png" if args.screenshot_dir else None
cases.append((name, f"?layout={template}", (width, height), screenshot))
diff --git a/scripts/editor-browser.html b/scripts/editor-browser.html
index a5e2b51..c95e1e4 100644
--- a/scripts/editor-browser.html
+++ b/scripts/editor-browser.html
@@ -281,10 +281,77 @@
Inline editor regression checks
const toolbar = role("editor-toolbar");
const panel = role("output-panel");
const rect = element => element.getBoundingClientRect();
+ const mobile = matchMedia("(max-width: 640px)").matches;
+ const compactActions = kind === "index" ? [] : [
+ ["reset-btn", "Reset"], ["format-btn", "Format"],
+ ...(kind === "exercise" ? [["vscode-btn", "Open in Web Editor"]] : []),
+ ];
+ // Copy is positioned over the code, outside the sticky toolbar. It need not
+ // be in the viewport during output checks, but must still be a touch target.
+ const copy = role("copy-btn");
+ if (kind === "exercise") assert(!!copy, "Exercise has a code copy control");
+ if (copy) {
+ assert(!toolbar.contains(copy), "Code copy control is outside the toolbar");
+ if (mobile) assert(rect(copy).width >= 44 && rect(copy).height >= 44, "Mobile code copy target is at least 44×44");
+ }
const visibleControls = label => {
const head = rect(toolbar);
const bar = rect(topbar);
assert(head.top >= bar.bottom - 1 && head.bottom <= innerHeight, `${label}: toolbar fits below navigation`);
+ const actions = toolbar.querySelector(".exercise-actions");
+ const buttons = [...toolbar.querySelectorAll(".btn")].filter(button => button.getClientRects().length);
+ if (mobile) {
+ const layout = getComputedStyle(toolbar);
+ const actionLayout = getComputedStyle(actions);
+ const area = rect(actions);
+ assert(layout.display === "flex" && layout.flexDirection === "column", `${label}: mobile toolbar stacks vertically`);
+ assert(actionLayout.display === "flex" && actionLayout.flexWrap === "wrap" && actionLayout.justifyContent === "flex-start", `${label}: mobile actions wrap and align left`);
+ const contentLeft = head.left + parseFloat(layout.borderLeftWidth) + parseFloat(layout.paddingLeft);
+ const contentRight = head.right - parseFloat(layout.borderRightWidth) - parseFloat(layout.paddingRight);
+ assert(Math.abs(area.left - contentLeft) <= 1 && Math.abs(area.right - contentRight) <= 1, `${label}: mobile actions span the toolbar content width`);
+ for (const button of buttons) {
+ const r = rect(button);
+ assert(r.width >= 44 && r.height >= 44, `${label}: ${button.dataset.role} mobile target is at least 44×44`);
+ const firstInRow = !buttons.some(other => Math.abs(rect(other).top - r.top) <= 1 && rect(other).left < r.left);
+ if (firstInRow) assert(Math.abs(r.left - area.left) <= 1, `${label}: mobile button row starts at the left edge`);
+ }
+ const status = role("action-status");
+ const statusLayout = getComputedStyle(status);
+ if (!status.textContent.trim()) {
+ assert(statusLayout.display === "none" && status.getClientRects().length === 0, `${label}: empty mobile status occupies no space`);
+ } else {
+ const r = rect(status);
+ assert(statusLayout.order === "1" && statusLayout.flexBasis === "100%", `${label}: mobile status is ordered as a full row`);
+ assert(r.height > 0 && statusLayout.visibility === "visible" && Number(statusLayout.opacity) > 0, `${label}: nonempty mobile status is visible`);
+ assert(Math.abs(r.left - area.left) <= 1 && Math.abs(r.right - area.right) <= 1 && r.bottom <= head.bottom + 1, `${label}: mobile status spans the action row within the toolbar`);
+ assert(buttons.every(button => r.top >= rect(button).bottom - 1), `${label}: mobile status occupies a separate row after all buttons`);
+ }
+ for (const cluster of actions.querySelectorAll(".actions-cluster-start")) {
+ assert(getComputedStyle(cluster).marginLeft === "0px", `${label}: mobile fullscreen cluster has no leading margin`);
+ }
+ }
+ for (const [name, text] of compactActions) {
+ const button = role(name);
+ const icon = button?.querySelector("svg.editor-action-icon");
+ const caption = button?.querySelector(".editor-action-label");
+ assert(!!icon && !!caption && caption.textContent.trim() === text, `${label}: ${name} retains its SVG and text label`);
+ assert(icon.getAttribute("aria-hidden") === "true", `${label}: ${name} icon is decorative`);
+ const captionStyle = getComputedStyle(caption);
+ const iconStyle = getComputedStyle(icon);
+ assert(!caption.closest('[aria-hidden="true"], [hidden], [inert]') && captionStyle.display !== "none" && captionStyle.visibility === "visible", `${label}: ${name} label remains available to accessibility`);
+ if (mobile) {
+ assert(iconStyle.display !== "none" && rect(icon).width > 1 && rect(icon).height > 1, `${label}: ${name} mobile icon is visible`);
+ assert(captionStyle.position === "absolute" && rect(caption).width <= 1 && rect(caption).height <= 1 && captionStyle.overflow === "hidden" && (captionStyle.clipPath !== "none" || captionStyle.clip !== "auto"), `${label}: ${name} mobile label is visually hidden, not removed`);
+ } else {
+ assert(iconStyle.display === "none" && icon.getClientRects().length === 0, `${label}: ${name} desktop icon is hidden`);
+ assert(rect(caption).width > 1 && rect(caption).height > 1 && captionStyle.clipPath === "none" && captionStyle.clip === "auto" && Number(captionStyle.opacity) > 0, `${label}: ${name} desktop label is presented normally`);
+ }
+ }
+ for (const name of ["run-btn", "submit-btn"]) {
+ const button = role(name);
+ if (!button?.getClientRects().length) continue;
+ assert(/Run|Submit/.test(button.innerText) && !button.querySelector(".editor-action-label"), `${label}: ${name} keeps its visible text label`);
+ }
for (const button of toolbar.querySelectorAll("button, a")) {
if (!button.getClientRects().length) continue;
const r = rect(button);
diff --git a/static/css/base.css b/static/css/base.css
index e06e500..02271a3 100644
--- a/static/css/base.css
+++ b/static/css/base.css
@@ -326,6 +326,69 @@ samp,
flex-wrap: wrap;
min-width: 0;
}
+.editor-action-icon {
+ display: none;
+}
+@media (max-width: 640px) {
+ .exercise-section > [data-role="editor-toolbar"] {
+ flex-direction: column;
+ align-items: stretch;
+ gap: 0.5rem;
+ }
+ [data-role="editor-toolbar"] > :empty {
+ display: none;
+ }
+ [data-role="editor-toolbar"] .exercise-actions {
+ width: 100%;
+ justify-content: flex-start;
+ gap: 0.5rem;
+ }
+ [data-role="editor-toolbar"] .exercise-actions .action-status {
+ order: 1;
+ flex-basis: 100%;
+ height: auto;
+ padding: 0.25rem 0;
+ white-space: normal;
+ }
+ [data-role="editor-toolbar"] .action-status:empty {
+ display: none;
+ }
+ [data-role="editor-toolbar"] .btn,
+ .exercise-section [data-role="copy-btn"] {
+ min-width: 44px;
+ min-height: 44px;
+ justify-content: center;
+ }
+ /* Saving changes the label to "Submitted"; keep its row stable. */
+ [data-role="editor-toolbar"] [data-role="submit-btn"] {
+ min-width: 8rem;
+ }
+ [data-role="editor-toolbar"] .btn:has(.editor-action-icon) {
+ width: 44px;
+ padding: 0;
+ }
+ [data-role="editor-toolbar"] .editor-action-icon {
+ display: block;
+ width: 20px;
+ height: 20px;
+ flex-shrink: 0;
+ }
+ /* Keep the name available to screen readers when only the icon is visible. */
+ [data-role="editor-toolbar"] .editor-action-label {
+ position: absolute;
+ width: 1px;
+ height: 1px;
+ padding: 0;
+ margin: -1px;
+ overflow: hidden;
+ clip-path: inset(50%);
+ white-space: nowrap;
+ border: 0;
+ }
+ [data-role="editor-toolbar"] .exercise-actions .actions-cluster-start {
+ margin-left: 0;
+ }
+}
[data-role="output-panel"] {
scroll-margin-top: calc(
var(--editor-topbar-height, 3rem) + var(--editor-toolbar-height, 0px) + 1rem
diff --git a/templates/exercise.html b/templates/exercise.html
index bbd5b95..d6355cd 100644
--- a/templates/exercise.html
+++ b/templates/exercise.html
@@ -205,7 +205,8 @@ {{ title }}
data-role="reset-btn"
title="Replace your edits with the original starter code"
>
- Reset
+
+ Reset
{% endif %} {% if exercise.shows_button("vscode") %}
{{ title }}
rel="noopener"
title="Open this file on github.dev (a browser-based VS Code)"
>
- Open in Web Editor
+
+ Open in Web Editor
{% endif %} {% if exercise.shows_button("format") %}
{% endif %} {% if exercise.shows_button("run") %}