From 179c5a7bcf3ea930f1728b2bbe981ec6efd63720 Mon Sep 17 00:00:00 2001 From: Ophir LOJKINE Date: Mon, 23 Nov 2026 21:33:55 +0100 Subject: [PATCH 1/9] Check component documentation accessibility in CI (#1634) * Audit official-site component docs with axe in CI * Audit component examples in SQLPage stock themes --- .github/workflows/ci.yml | 34 +++- CHANGELOG.md | 1 + CONTRIBUTING.md | 5 + examples/official-site/README.md | 4 + .../official-site/assets/docs/examples.css | 68 ++++---- examples/official-site/sqlpage/docs-shell.sql | 4 + .../sqlpage/templates/shell-docs.handlebars | 6 +- package-lock.json | 53 +++++-- .../official-site-accessibility.spec.ts | 150 ++++++++++++++++++ tests/end-to-end/package.json | 1 + 10 files changed, 275 insertions(+), 51 deletions(-) create mode 100644 tests/end-to-end/official-site-accessibility.spec.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 808d8bab7..f3ad73c91 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,8 +12,6 @@ on: - ".github/workflows/release.yml" # Required checks must be reported for every PR, including docs-only changes. pull_request: - branches: - - "main" merge_group: concurrency: @@ -29,23 +27,41 @@ jobs: ci_selection: runs-on: ubuntu-latest permissions: + contents: read pull-requests: read outputs: # Only a confirmed excluded-files-only PR may skip the core jobs. full: ${{ github.event_name != 'pull_request' || steps.paths.outputs.full != 'false' }} + # Run the audit when a tag or oversized PR cannot be filtered. + accessibility: ${{ steps.paths.outputs.accessibility != 'false' }} steps: + - uses: actions/checkout@v7 + if: github.event_name != 'pull_request' && github.ref_type != 'tag' - id: paths name: Select test jobs # The PR files API is limited to 3000 files; larger PRs select core jobs. - if: github.event_name == 'pull_request' && github.event.pull_request.changed_files <= 3000 + if: github.ref_type != 'tag' && (github.event_name != 'pull_request' || github.event.pull_request.changed_files <= 3000) uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4.0.3 with: - predicate-quantifier: every + predicate-quantifier: some-with-excludes filters: | full: + - '**' - '!docs/**' - '!README.md' - '!.github/workflows/release.yml' + accessibility: + - 'sqlpage/templates/**' + - 'frontend/**' + - 'src/{dynamic_component,render,template_helpers,templates}.rs' + - 'examples/official-site/**' + - 'configuration.md' + - 'scripts/{build-frontend,site-build}.mjs' + - 'package-lock.json' + - 'package.json' + - 'tests/end-to-end/**' + - '.github/actions/install-frontend-dependencies/**' + - '.github/workflows/ci.yml' compile_and_lint: needs: ci_selection @@ -233,7 +249,7 @@ jobs: playwright: runs-on: ubuntu-latest timeout-minutes: 10 - needs: compile_and_lint + needs: [ci_selection, compile_and_lint] defaults: run: working-directory: ./tests/end-to-end @@ -257,9 +273,15 @@ jobs: name: official-site path: target/official-site - name: Run Playwright tests + env: + RUN_ACCESSIBILITY: ${{ needs.ci_selection.outputs.accessibility }} run: | chmod +x "${{ runner.temp }}/sqlpage-bin/sqlpage" - SQLPAGE_BINARY="${{ runner.temp }}/sqlpage-bin/sqlpage" npx playwright test + args=() + if [[ "$RUN_ACCESSIBILITY" == false ]]; then + args+=(--grep-invert @accessibility) + fi + SQLPAGE_BINARY="${{ runner.temp }}/sqlpage-bin/sqlpage" npx playwright test "${args[@]}" - uses: actions/upload-artifact@v7 if: ${{ !cancelled() }} with: diff --git a/CHANGELOG.md b/CHANGELOG.md index 62ce81fd5..82a32f5ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## unreleased +- Component reference pages accept `theme=light` and `theme=dark` to preview examples with SQLPage's stock themes. - The first-website tutorial now lets you choose an installation target, copy a command, or download an archive for macOS, Windows, Linux, or AWS Lambda. - Missing component pages on the official site return HTTP 404 and link to the catalog. Action buttons in colored alerts stay readable. - The `shell` sidebar now uses `navbar_title` and preserves the colors of the supplied logo in dark mode. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e55e268c6..38d8519ba 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -67,6 +67,11 @@ built executable. Component suites use `fixtures//{index.sql,test.ts}` an import the shared `fixture.ts` harness; root-level `*.spec.ts` files cover the official site. +Run `npx playwright test --grep @accessibility` from `tests/end-to-end` to audit +the official site's component documentation and its live examples in SQLPage's +stock light and dark themes with axe-core. CI includes this test when component +templates, frontend code, the official site, or audit inputs change. + To show that an issue exists before you fix it, put the reproduction in a fixture and run it against releases with one command, such as `nix run .#reproduce -- repro_721 postgres v0.35.0 v0.36.1 tree`. The second argument is `sqlite` or `postgres`, and `tree` is your working tree. It prints Playwright's output for each version, then a table you can paste into the issue or pull request. Releases run from their Docker images, from v0.29.0 onwards, and Postgres from `docker compose`. Without Nix, run `npm run reproduce --` in `tests/end-to-end` instead. To run a whole suite against a release instead, set `SQLPAGE_RELEASE` to its tag, such as `SQLPAGE_RELEASE=v0.47.0 npx playwright test fixtures/tracking`. Both servers then run that release's Docker image against the same fixtures, on ports 18080 and 18081, so the test fails on the release and passes on your working tree. Add `--ui` to watch the page in each step. diff --git a/examples/official-site/README.md b/examples/official-site/README.md index 5c5fa9440..f44983a13 100644 --- a/examples/official-site/README.md +++ b/examples/official-site/README.md @@ -22,6 +22,10 @@ Run SQLPage from that directory, or run `docker compose -f examples/official-site/docker-compose.yml up --build` from the repository root. +Add `theme=light` or `theme=dark` to a component reference URL to preview its +live examples using SQLPage's stock theme. For example, visit +`/component.sql?component=form&theme=light`. + ## Landing page The home page is rendered by `index.sql` and the `landing-page` custom template. diff --git a/examples/official-site/assets/docs/examples.css b/examples/official-site/assets/docs/examples.css index 134c5f923..77fe5da52 100644 --- a/examples/official-site/assets/docs/examples.css +++ b/examples/official-site/assets/docs/examples.css @@ -16,44 +16,52 @@ display: flow-root; container-type: inline-size; padding: var(--tblr-spacer-3); +} + +/* The branded previews adjust native components to fit the docs layout. */ +:where([data-site-theme="custom-docsite"]) .docs-example-output { --tblr-carousel-control-icon-filter: none; --tblr-carousel-indicator-active-bg: var(--tblr-heading-color); -} -/* Tabler sizes columns against the viewport. A card in a preview can have much less room. */ -.docs-example-output > .row > * { - flex-grow: 1; - min-width: min(100%, 17rem); -} -.docs-example-output form .row > label { - min-width: min(100%, 12rem); -} -.docs-example-output .card { - max-width: 100%; -} -.docs-example-output .table-freeze-columns tr > :first-child { - width: clamp(7rem, 32cqi, 11rem); - min-width: min(9rem, 40cqi); - white-space: normal; -} -.docs-example-output .pagination { - flex-wrap: wrap; -} -.docs-example-output .markdown table { - display: block; - overflow-x: auto; + + /* Preview columns can have much less room than the viewport. */ + & > .row > * { + flex-grow: 1; + min-width: min(100%, 17rem); + } + & form .row > label { + min-width: min(100%, 12rem); + } + & .card { + max-width: 100%; + } + & .table-freeze-columns tr > :first-child { + width: clamp(7rem, 32cqi, 11rem); + min-width: min(9rem, 40cqi); + white-space: normal; + } + & .pagination { + flex-wrap: wrap; + } + & .markdown table { + display: block; + overflow-x: auto; + } + + @media (max-width: 27rem) { + /* Give charts the full preview width while keeping the titles inset. */ + &:has(> .card > .card-body > .chart) { + padding-inline: 0; + } + & > .card > .card-body > .chart { + margin-inline: calc(-1 * var(--tblr-card-spacer-x)); + } + } } @media (max-width: 27rem) { .docs-example > .docs-example-source, .docs-example-layout { margin-inline: calc(var(--tblr-spacer-1) - var(--docs-gutter)); } - /* A chart card fills the preview. Keep its title inset and give the plot the full width. */ - .docs-example-output:has(> .card > .card-body > .chart) { - padding-inline: 0; - } - .docs-example-output > .card > .card-body > .chart { - margin-inline: calc(-1 * var(--tblr-card-spacer-x)); - } } @container example (min-width: 52rem) { .docs-example-layout { diff --git a/examples/official-site/sqlpage/docs-shell.sql b/examples/official-site/sqlpage/docs-shell.sql index ded481c17..364127321 100644 --- a/examples/official-site/sqlpage/docs-shell.sql +++ b/examples/official-site/sqlpage/docs-shell.sql @@ -7,6 +7,10 @@ select 'shell-docs' as component, $options->>'title' as title, $options->>'description' as description, $options->>'css' as css, + case sqlpage.variables('get')->>'theme' + when 'light' then 'light' + when 'dark' then 'dark' + end as stock_theme, $section as section, cast($catalog as integer) as catalog, coalesce($kind || 's', 'guides') as topic_label, diff --git a/examples/official-site/sqlpage/templates/shell-docs.handlebars b/examples/official-site/sqlpage/templates/shell-docs.handlebars index 30dfc4a1f..59e4b9c11 100644 --- a/examples/official-site/sqlpage/templates/shell-docs.handlebars +++ b/examples/official-site/sqlpage/templates/shell-docs.handlebars @@ -1,5 +1,5 @@ - + @@ -12,7 +12,9 @@ - + {{#unless stock_theme}} + + {{/unless}} {{#if catalog}} diff --git a/package-lock.json b/package-lock.json index d6d8f9697..3491092d5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,6 +25,22 @@ "typescript": "^7.0.2" } }, + "node_modules/@axe-core/playwright": { + "version": "4.14.0", + "resolved": "https://registry.npmjs.org/@axe-core/playwright/-/playwright-4.14.0.tgz", + "integrity": "sha512-SGUhG5PIHd2eMdpgBF2PyQLOhX+qyDR2PT4cmoS4Qk2ak+jX/rrSvst9l0PGv5WTHolKpUMvVmoHpr4cZgf1RQ==", + "dev": true, + "license": "MPL-2.0", + "dependencies": { + "axe-core": "~4.14.0" + }, + "engines": { + "node": ">=22.12.0" + }, + "peerDependencies": { + "playwright-core": ">= 1.0.0" + } + }, "node_modules/@biomejs/biome": { "version": "2.6.6", "resolved": "https://registry.npmjs.org/@biomejs/biome/-/biome-2.6.6.tgz", @@ -1069,10 +1085,33 @@ "node": "^20.19.0 || ^22.12.0 || >=24.0.0" } }, + "node_modules/axe-core": { + "version": "4.14.1", + "resolved": "https://registry.npmjs.org/axe-core/-/axe-core-4.14.1.tgz", + "integrity": "sha512-FHfa+lmNjQZfJz1q8wKqIDwC6DExcHt/pkjNQb09a3NPjCKg2rhu5qb2S4r76ASyFNNtuFooJpZe37OgudVGtQ==", + "dev": true, + "license": "MPL-2.0", + "engines": { + "node": ">=4" + } + }, "node_modules/end-to-end": { "resolved": "tests/end-to-end", "link": true }, + "node_modules/playwright-core": { + "version": "1.64.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.64.1.tgz", + "integrity": "sha512-BC4s8y6SEVA6Q1rSxZTto8hI1KUI3xXlHGZgvGqP4IqPdI/a6FX9H29IDNz7vKo9l21b6LfYosScPL6M3xxyDQ==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=20" + } + }, "node_modules/rolldown": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.3.1.tgz", @@ -1179,6 +1218,7 @@ "version": "1.0.0", "license": "ISC", "devDependencies": { + "@axe-core/playwright": "^4.14.0", "@playwright/test": "~1.64.1" } }, @@ -1213,19 +1253,6 @@ "engines": { "node": ">=20" } - }, - "tests/end-to-end/node_modules/playwright-core": { - "version": "1.64.1", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.64.1.tgz", - "integrity": "sha512-BC4s8y6SEVA6Q1rSxZTto8hI1KUI3xXlHGZgvGqP4IqPdI/a6FX9H29IDNz7vKo9l21b6LfYosScPL6M3xxyDQ==", - "dev": true, - "license": "Apache-2.0", - "bin": { - "playwright-core": "cli.js" - }, - "engines": { - "node": ">=20" - } } } } diff --git a/tests/end-to-end/official-site-accessibility.spec.ts b/tests/end-to-end/official-site-accessibility.spec.ts new file mode 100644 index 000000000..5b376be04 --- /dev/null +++ b/tests/end-to-end/official-site-accessibility.spec.ts @@ -0,0 +1,150 @@ +import { AxeBuilder } from "@axe-core/playwright"; +import { expect, test } from "@playwright/test"; + +const wcagTags = ["wcag2a", "wcag2aa", "wcag21a", "wcag21aa", "wcag22aa"]; + +// Existing failures in the documentation search shortcut and inline prose links. +const sharedRulesToFix = ["label-content-name-mismatch", "link-in-text-block"]; + +// Re-enable each rule for the affected component once its examples pass. +const componentRulesToFix: Partial> = { + button: ["color-contrast", "image-alt"], + card: ["color-contrast", "frame-title", "image-alt"], + carousel: ["button-name"], + code: ["scrollable-region-focusable"], + login: ["image-alt"], + map: ["color-contrast"], + pagination: ["link-name"], + table: ["scrollable-region-focusable"], + tracking: ["aria-prohibited-attr"], +}; + +const stockThemes = ["light", "dark"] as const; +type StockTheme = (typeof stockThemes)[number]; + +// Keep the rules active so additional failing elements exceed the baseline. +const stockBaseline: Partial< + Record>>> +> = { + alert: { + "color-contrast": { light: 7 }, + "link-in-text-block": { light: 1, dark: 1 }, + }, + big_number: { "color-contrast": { light: 6, dark: 4 } }, + button: { + "color-contrast": { light: 4, dark: 5 }, + "image-alt": { light: 1, dark: 1 }, + }, + card: { + "color-contrast": { light: 6, dark: 7 }, + "frame-title": { light: 1, dark: 1 }, + "image-alt": { light: 3, dark: 3 }, + }, + carousel: { "button-name": { light: 4, dark: 4 } }, + datagrid: { "color-contrast": { light: 3, dark: 2 } }, + divider: { "color-contrast": { dark: 1 } }, + foldable: { "link-in-text-block": { light: 1, dark: 1 } }, + list: { "color-contrast": { light: 1 } }, + login: { + "image-alt": { light: 1, dark: 1 }, + "link-in-text-block": { dark: 1 }, + }, + map: { "color-contrast": { dark: 3 } }, + modal: { "color-contrast": { light: 2, dark: 1 } }, + pagination: { "link-name": { light: 8, dark: 8 } }, + status_bar: { "color-contrast": { light: 1 } }, + steps: { "color-contrast": { light: 2, dark: 2 } }, + tab: { "color-contrast": { dark: 2 } }, + table: { + "color-contrast": { light: 13, dark: 1 }, + "scrollable-region-focusable": { light: 1, dark: 1 }, + }, + text: { "link-in-text-block": { light: 4, dark: 4 } }, + timeline: { "link-in-text-block": { light: 1, dark: 1 } }, + tracking: { "aria-prohibited-attr": { light: 16, dark: 16 } }, +}; + +test("component documentation passes axe WCAG A and AA checks", { + tag: "@accessibility", +}, async ({ page }) => { + test.setTimeout(180_000); + + // Keep the video iframe in the audit, without loading YouTube's UI. + await page.route("https://www.youtube.com/embed/**", (route) => + route.fulfill({ status: 204 }), + ); + + const catalog = await page.goto("/components.sql"); + expect(catalog?.ok()).toBe(true); + const links = page.locator('#catalog a[href^="/component.sql?component="]'); + await expect(links.first()).toBeVisible(); + const urls = await links.evaluateAll((anchors) => + anchors.map((anchor) => (anchor as HTMLAnchorElement).href), + ); + + const liveExamples = ".docs-example-output"; + for (const href of new Set(urls)) { + const url = new URL(href); + const component = url.searchParams.get("component") ?? ""; + let previewCount = 0; + + for (const theme of ["custom-docsite", ...stockThemes] as const) { + const stockTheme = theme === "custom-docsite" ? undefined : theme; + if (stockTheme) url.searchParams.set("theme", stockTheme); + await test.step(`${component} (${theme})`, async () => { + const response = await page.goto(url.href); + expect(response?.ok()).toBe(true); + await expect( + page.getByRole("heading", { + name: `The ${component} component`, + level: 1, + exact: true, + }), + ).toBeVisible(); + + const axe = new AxeBuilder({ page }).withTags(wcagTags); + const previews = page.locator(liveExamples); + if (stockTheme) { + const html = page.locator("html"); + await expect(html).toHaveAttribute("data-bs-theme", stockTheme); + await expect(html).not.toHaveAttribute( + "data-site-theme", + "custom-docsite", + ); + await expect( + page.locator( + 'link[href="/assets/highlightjs-and-tabler-theme.css"]', + ), + ).toHaveCount(0); + await expect(previews).toHaveCount(previewCount); + if (previewCount === 0) return; + axe.include(liveExamples); + } else { + previewCount = await previews.count(); + axe.disableRules([ + ...sharedRulesToFix, + ...(componentRulesToFix[component] ?? []), + ]); + } + + const { violations } = await axe.analyze(); + const regressions = violations + .map(({ id, helpUrl, nodes }) => ({ + id, + helpUrl, + baseline: stockTheme + ? (stockBaseline[component]?.[id]?.[stockTheme] ?? 0) + : 0, + nodes: nodes.map(({ target, failureSummary }) => ({ + target, + failureSummary, + })), + })) + .filter(({ nodes, baseline }) => nodes.length > baseline); + expect + .soft(regressions, `${component} (${theme}) accessibility violations`) + .toEqual([]); + }); + } + } +}); diff --git a/tests/end-to-end/package.json b/tests/end-to-end/package.json index b89c7331a..925398d5b 100644 --- a/tests/end-to-end/package.json +++ b/tests/end-to-end/package.json @@ -13,6 +13,7 @@ "author": "", "license": "ISC", "devDependencies": { + "@axe-core/playwright": "^4.14.0", "@playwright/test": "~1.64.1" } } From 6836e8e63e462eab4ccfe97ddb7dc6c1b2ac6bd8 Mon Sep 17 00:00:00 2001 From: lovasoa Date: Mon, 23 Nov 2026 21:40:26 +0100 Subject: [PATCH 2/9] Improve accessibility of navigation and tracking components --- CHANGELOG.md | 3 +++ sqlpage/templates/carousel.handlebars | 2 +- sqlpage/templates/pagination.handlebars | 16 ++++++++-------- sqlpage/templates/tracking.handlebars | 2 +- tests/end-to-end/fixtures/carousel/index.sql | 3 +++ tests/end-to-end/fixtures/carousel/test.ts | 6 ++++++ tests/end-to-end/fixtures/pagination/index.sql | 3 +++ tests/end-to-end/fixtures/pagination/test.ts | 16 ++++++++++++++++ tests/end-to-end/fixtures/tracking/test.ts | 5 +++++ .../official-site-accessibility.spec.ts | 6 ------ 10 files changed, 46 insertions(+), 16 deletions(-) create mode 100644 tests/end-to-end/fixtures/carousel/index.sql create mode 100644 tests/end-to-end/fixtures/carousel/test.ts create mode 100644 tests/end-to-end/fixtures/pagination/index.sql create mode 100644 tests/end-to-end/fixtures/pagination/test.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 82a32f5ba..a8d2e9a23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## unreleased +- Carousel slide indicators and pagination controls now have accessible names. Enabled pagination controls are reachable by keyboard and no longer announced as disabled. +- Tracking blocks without links now expose their titles to screen readers. + - Component reference pages accept `theme=light` and `theme=dark` to preview examples with SQLPage's stock themes. - The first-website tutorial now lets you choose an installation target, copy a command, or download an archive for macOS, Windows, Linux, or AWS Lambda. - Missing component pages on the official site return HTTP 404 and link to the catalog. Action buttons in colored alerts stay readable. diff --git a/sqlpage/templates/carousel.handlebars b/sqlpage/templates/carousel.handlebars index d65762edb..c03834361 100644 --- a/sqlpage/templates/carousel.handlebars +++ b/sqlpage/templates/carousel.handlebars @@ -8,7 +8,7 @@