Skip to content

Commit b19d95b

Browse files
authored
Axe overlay polish: left-align report and scroll highlighted elements clear of it (#14680)
Three quality-of-life fixes to the `axe: output: document` fixed overlay in HTML output. - Left-align the report text. The overlay is appended into `<main>`, so page-level centering (e.g. `about: template: jolla`) leaked into the report; the base overlay rule now pins `text-align: left` like the reveal report slide already does. - Scroll highlighted elements clear of the overlay. Hovering a selector scrolled the target with `scrollIntoView({block: "center"})`, which could land a centered full-width element under the fixed `bottom/right` overlay. A new exported pure helper, `overlayAwareScrollTop`, centers the element in the viewport band above the overlay; elements with no horizontal overlap keep default centering. Only the plain-HTML fixed overlay takes this path. - Make the overlay pass its own scan. axe-core flagged `scrollable-region-focusable` (serious, WCAG 2.1.1) once the report exceeded `max-height: 50vh` and scrolled. The overlay is now a focusable labeled region (`tabindex="0"`, `role="region"`, `aria-label`) in the fixed-overlay path. Covered by unit tests for the helper geometry, a Playwright hover test, HTML overlay assertions, and an axe-core self-scan regression test.
1 parent 22e8518 commit b19d95b

6 files changed

Lines changed: 295 additions & 0 deletions

File tree

‎news/changelog-1.10.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ All changes included in 1.10:
2121
- ([#14655](https://github.com/quarto-dev/quarto-cli/issues/14655)): Add accessible names to code line-number links so screen readers and accessibility audits no longer report them as empty links.
2222
- ([#14676](https://github.com/quarto-dev/quarto-cli/pull/14676)): The `axe` accessibility report UI now lists violations most-important-first: by impact (critical first), then WCAG conformance level (A before AA, current criteria before Best Practice and obsolete ones), then rule id. `output: json` still emits axe-core's raw, unsorted result.
2323
- ([#14677](https://github.com/quarto-dev/quarto-cli/pull/14677)): The `axe` option now uses a copy of axe-core bundled with Quarto instead of loading it from the Skypack CDN in the reader's browser. Accessibility checking now works offline, and viewing a rendered document no longer triggers a request to `cdn.skypack.dev`. The axe-core version is unchanged (4.10.3), so scan results are identical.
24+
- ([#14680](https://github.com/quarto-dev/quarto-cli/pull/14680)): Fix the `axe` accessibility report overlay inheriting page-level text centering (e.g. from the `jolla` about template) in HTML output; the overlay is now always left-aligned.
25+
- ([#14680](https://github.com/quarto-dev/quarto-cli/pull/14680)): Fix hovering a selector in the `axe` accessibility report overlay scrolling the highlighted element underneath the overlay; the element now settles in the viewport area above the report.
26+
- ([#14680](https://github.com/quarto-dev/quarto-cli/pull/14680)): Fix the `axe` accessibility report overlay in HTML output failing axe's own `scrollable-region-focusable` rule: a report long enough to scroll could not be scrolled by keyboard. The overlay is now a focusable, labeled region.
2427

2528
## Formats
2629

‎src/format/html/format-html-axe.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ body div.quarto-axe-report {
6262
color: var(--r-main-color, #222);
6363
max-height: 50vh;
6464
overflow-y: auto;
65+
/* The overlay lives inside <main>, so it inherits page-level centering
66+
(e.g. the jolla about template centers main). Pin it left. */
67+
text-align: left;
6568
}
6669
6770
.quarto-axe-violation-help { padding-left: 0.5rem; }

‎src/resources/formats/html/axe/axe-check.js‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,38 @@ export function compareViolations(a, b) {
7373
);
7474
}
7575

76+
// Margin kept between the viewport top and an element too tall to center in
77+
// the band above the report overlay.
78+
const OVERLAY_SCROLL_MARGIN = 16;
79+
80+
// Compute the document scrollTop that positions an element in the viewport band
81+
// the fixed report overlay does NOT cover, so scrolling a highlighted element
82+
// into view can't park it underneath the report. The overlay is bottom-anchored,
83+
// so that band runs from the viewport top down to the overlay's top edge.
84+
// Returns null when default `block: "center"` scrolling can't be obscured (no
85+
// horizontal overlap with the overlay) or when the overlay leaves no usable
86+
// band. All inputs are viewport-relative rects plus scroll state, so this stays
87+
// a pure function (unit-testable without a DOM, like axeConformanceLevel).
88+
export function overlayAwareScrollTop(
89+
elementRect,
90+
overlayRect,
91+
viewportHeight,
92+
scrollY,
93+
) {
94+
// Element entirely left of the overlay: centering can't obscure it.
95+
if (elementRect.right <= overlayRect.left) return null;
96+
97+
const bandHeight = Math.min(overlayRect.top, viewportHeight);
98+
if (bandHeight <= OVERLAY_SCROLL_MARGIN * 2) return null;
99+
100+
const offset = elementRect.height > bandHeight
101+
// Too tall to fit in the band: align its start just inside the top.
102+
? OVERLAY_SCROLL_MARGIN
103+
// Otherwise center it within the band.
104+
: bandHeight / 2 - elementRect.height / 2;
105+
return Math.max(0, scrollY + elementRect.top - offset);
106+
}
107+
76108
class QuartoAxeReporter {
77109
constructor(axeResult, options) {
78110
this.axeResult = axeResult;
@@ -140,6 +172,22 @@ class QuartoAxeDocumentReporter extends QuartoAxeReporter {
140172
element.scrollIntoView({ behavior: "smooth", block: "center" });
141173
}
142174
} else {
175+
// Only the plain-HTML fixed overlay can obscure a centered element:
176+
// Reveal navigates slides, and the dashboard offcanvas is a static,
177+
// full-height side panel that vertical scrolling can't dodge.
178+
const report = document.querySelector(".quarto-axe-report");
179+
if (report && getComputedStyle(report).position === "fixed") {
180+
const top = overlayAwareScrollTop(
181+
element.getBoundingClientRect(),
182+
report.getBoundingClientRect(),
183+
window.innerHeight,
184+
window.scrollY,
185+
);
186+
if (top !== null) {
187+
window.scrollTo({ top, behavior: "smooth" });
188+
return;
189+
}
190+
}
143191
element.scrollIntoView({ behavior: "smooth", block: "center" });
144192
}
145193
}
@@ -208,6 +256,15 @@ class QuartoAxeDocumentReporter extends QuartoAxeReporter {
208256

209257
createReportOverlay() {
210258
const reportElement = this.createReportElement();
259+
// The fixed overlay scrolls (max-height: 50vh + overflow-y: auto), so it
260+
// must be keyboard-focusable or it fails axe's own
261+
// scrollable-region-focusable rule once the report overflows. The role and
262+
// label give the resulting tab stop an accessible name. The reveal slide
263+
// and dashboard offcanvas variants don't scroll the report element itself,
264+
// so they skip the extra tab stop.
265+
reportElement.tabIndex = 0;
266+
reportElement.setAttribute("role", "region");
267+
reportElement.setAttribute("aria-label", "Accessibility report");
211268
(document.querySelector("main") || document.body).appendChild(reportElement);
212269
}
213270

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
format:
3+
html:
4+
axe:
5+
output: document
6+
---
7+
8+
## Long Document
9+
10+
The dozen violations below inflate the report to its `max-height: 50vh`, so the
11+
fixed overlay really covers the lower half of the viewport — with only one
12+
violation the report is short and even default centered scrolling clears it.
13+
14+
[low contrast 1]{#c1 style="color: #eee; background: #fff;"}
15+
16+
[low contrast 2]{#c2 style="color: #eee; background: #fff;"}
17+
18+
[low contrast 3]{#c3 style="color: #eee; background: #fff;"}
19+
20+
[low contrast 4]{#c4 style="color: #eee; background: #fff;"}
21+
22+
[low contrast 5]{#c5 style="color: #eee; background: #fff;"}
23+
24+
[low contrast 6]{#c6 style="color: #eee; background: #fff;"}
25+
26+
[low contrast 7]{#c7 style="color: #eee; background: #fff;"}
27+
28+
[low contrast 8]{#c8 style="color: #eee; background: #fff;"}
29+
30+
[low contrast 9]{#c9 style="color: #eee; background: #fff;"}
31+
32+
[low contrast 10]{#c10 style="color: #eee; background: #fff;"}
33+
34+
[low contrast 11]{#c11 style="color: #eee; background: #fff;"}
35+
36+
[low contrast 12]{#c12 style="color: #eee; background: #fff;"}
37+
38+
Filler so the page scrolls well past one viewport; the hovered violation sits
39+
near the bottom where centering it would put it under the report overlay.
40+
41+
::: {style="height: 3000px;"}
42+
:::
43+
44+
::: {#bottom-contrast style="color: #eee; background: #fff;"}
45+
This full-width block near the bottom of the page violates contrast rules, so
46+
its bounding box overlaps the report overlay horizontally.
47+
:::
48+
49+
::: {style="height: 400px;"}
50+
:::

‎tests/integration/playwright/tests/axe-accessibility.spec.ts‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,17 @@ test.describe('Axe accessibility checking', () => {
162162
await expect(axeReport).toHaveCSS('z-index', '9999');
163163
await expect(axeReport).toHaveCSS('overflow-y', 'auto');
164164

165+
// Overlay must not inherit page-level centering (e.g. about
166+
// templates center <main>, which the overlay is appended into)
167+
await expect(axeReport).toHaveCSS('text-align', 'left');
168+
169+
// The overlay scrolls when the report overflows, so it must be a
170+
// focusable, labeled region or it fails axe's own
171+
// scrollable-region-focusable rule
172+
await expect(axeReport).toHaveAttribute('tabindex', '0');
173+
await expect(axeReport).toHaveAttribute('role', 'region');
174+
await expect(axeReport).toHaveAttribute('aria-label', 'Accessibility report');
175+
165176
// Background must not be transparent
166177
await expect(axeReport).not.toHaveCSS('background-color', 'rgba(0, 0, 0, 0)');
167178
}
@@ -338,6 +349,65 @@ test.describe('HTML axe — hover interaction and highlight', () => {
338349
});
339350
});
340351

352+
test.describe('HTML axe — hover scrolls element clear of the report overlay', () => {
353+
test('highlighted element settles above the overlay, not under it', async ({ page }) => {
354+
await page.goto('/html/axe-overlay-scroll.html', { waitUntil: 'networkidle' });
355+
356+
const axeReport = page.locator('.quarto-axe-report');
357+
await expect(axeReport).toBeVisible({ timeout: 10000 });
358+
359+
// Hover the selector for the full-width violation near the page bottom.
360+
// Default block:center scrolling would land it under the bottom-right
361+
// fixed overlay; the overlay-aware scroll targets the band above it.
362+
const target = axeReport.locator('.quarto-axe-violation-target', {
363+
hasText: '#bottom-contrast',
364+
});
365+
await target.hover();
366+
367+
// axe targets the text-bearing element (the <p> inside #bottom-contrast,
368+
// e.g. "#bottom-contrast > p"), so locate the highlight by class rather
369+
// than assuming the exact selector.
370+
const element = page.locator('.quarto-axe-hover-highlight');
371+
await expect(element).toBeAttached({ timeout: 3000 });
372+
373+
// Poll until the smooth scroll settles with the element fully inside the
374+
// viewport band above the overlay.
375+
await expect.poll(async () => {
376+
const elementBox = await element.boundingBox();
377+
const overlayBox = await axeReport.boundingBox();
378+
if (!elementBox || !overlayBox) return 'missing bounding box';
379+
if (elementBox.y < 0) return `element top ${elementBox.y} above viewport`;
380+
if (elementBox.y + elementBox.height > overlayBox.y) {
381+
return `element bottom ${elementBox.y + elementBox.height} below overlay top ${overlayBox.y}`;
382+
}
383+
return 'clear of overlay';
384+
}, { timeout: 5000 }).toBe('clear of overlay');
385+
});
386+
});
387+
388+
test.describe('HTML axe — the report overlay passes its own scan', () => {
389+
test('overlay has no axe-core violations', async ({ page }) => {
390+
// The overlay is injected after the page scan runs, so it never audits
391+
// itself. Scan it here with the same vendored axe-core build the page
392+
// already loaded (window.axe), on the long-report page where the overlay
393+
// is scrollable — the state that tripped scrollable-region-focusable.
394+
await page.goto('/html/axe-overlay-scroll.html', { waitUntil: 'networkidle' });
395+
396+
const axeReport = page.locator('.quarto-axe-report');
397+
await expect(axeReport).toBeVisible({ timeout: 10000 });
398+
399+
const violations = await page.evaluate(async () => {
400+
const axe = (window as any).axe;
401+
const result = await axe.run(document.querySelector('.quarto-axe-report'));
402+
return result.violations.map((v: { id: string; nodes: { target: string[] }[] }) => ({
403+
id: v.id,
404+
targets: v.nodes.map((n) => n.target),
405+
}));
406+
});
407+
expect(violations).toEqual([]);
408+
});
409+
});
410+
341411
test.describe('Dashboard axe — re-scan on visibility change', () => {
342412
const pagesUrl = '/dashboard/axe-accessibility-pages.html';
343413

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* axe-overlay-scroll.test.ts
3+
*
4+
* Tests the scroll-target computation the axe document reporter uses to keep a
5+
* highlighted element from landing underneath the fixed report overlay.
6+
*
7+
* `overlayAwareScrollTop` is a pure function of viewport-relative rects and
8+
* scroll state, so these tests need no DOM: each case hand-constructs the rects
9+
* and asserts either the returned scrollTop or null (which tells the caller to
10+
* keep the default `scrollIntoView({block: "center"})` behavior).
11+
*
12+
* Copyright (C) 2020-2025 Posit Software, PBC
13+
*/
14+
15+
import { unitTest } from "../test.ts";
16+
import { assertEquals } from "testing/asserts";
17+
import { overlayAwareScrollTop } from "../../src/resources/formats/html/axe/axe-check.js";
18+
19+
// A bottom-right overlay in a 1280x720 viewport: top edge at y=400, left edge
20+
// at x=800. The unobscured band above it is [0, 400], centered at y=200.
21+
const overlay = { top: 400, left: 800 };
22+
const viewportHeight = 720;
23+
24+
unitTest(
25+
"overlayAwareScrollTop - no horizontal overlap returns null",
26+
// deno-lint-ignore require-await
27+
async () => {
28+
// Element's right edge (700) is left of the overlay's left edge (800), so
29+
// default centering can't put it under the overlay.
30+
assertEquals(
31+
overlayAwareScrollTop(
32+
{ top: 600, right: 700, height: 100 },
33+
overlay,
34+
viewportHeight,
35+
1000,
36+
),
37+
null,
38+
);
39+
},
40+
);
41+
42+
unitTest(
43+
"overlayAwareScrollTop - overlapping element is centered in the band above the overlay",
44+
// deno-lint-ignore require-await
45+
async () => {
46+
// Element at viewport y=600, height 100. Centering it at the band's center
47+
// (y=200) means its top must land at y=150, i.e. scroll down 450 more:
48+
// 1000 + 600 - (400/2 - 100/2) = 1450.
49+
assertEquals(
50+
overlayAwareScrollTop(
51+
{ top: 600, right: 1100, height: 100 },
52+
overlay,
53+
viewportHeight,
54+
1000,
55+
),
56+
1450,
57+
);
58+
},
59+
);
60+
61+
unitTest(
62+
"overlayAwareScrollTop - element taller than the band is top-aligned with a margin",
63+
// deno-lint-ignore require-await
64+
async () => {
65+
// Height 500 exceeds the 400px band, so align its start just inside the
66+
// viewport top instead of centering: 1000 + 600 - 16 = 1584.
67+
assertEquals(
68+
overlayAwareScrollTop(
69+
{ top: 600, right: 1100, height: 500 },
70+
overlay,
71+
viewportHeight,
72+
1000,
73+
),
74+
1584,
75+
);
76+
},
77+
);
78+
79+
unitTest(
80+
"overlayAwareScrollTop - scrollTop is clamped at the document top",
81+
// deno-lint-ignore require-await
82+
async () => {
83+
// Centering would need scrollTop 0 + 50 - 150 = -100; clamp to 0.
84+
assertEquals(
85+
overlayAwareScrollTop(
86+
{ top: 50, right: 1100, height: 100 },
87+
overlay,
88+
viewportHeight,
89+
0,
90+
),
91+
0,
92+
);
93+
},
94+
);
95+
96+
unitTest(
97+
"overlayAwareScrollTop - degenerate band (overlay covers the viewport) returns null",
98+
// deno-lint-ignore require-await
99+
async () => {
100+
// Overlay top edge nearly at the viewport top leaves no usable band to
101+
// scroll the element into; fall back to default centering.
102+
assertEquals(
103+
overlayAwareScrollTop(
104+
{ top: 600, right: 1100, height: 100 },
105+
{ top: 20, left: 100 },
106+
viewportHeight,
107+
1000,
108+
),
109+
null,
110+
);
111+
},
112+
);

0 commit comments

Comments
 (0)