An open source design system that's fully customizable and agent ready
TypeScript
fix(core): reset.css leaves hidden="until-found" content findable (#7520)
Christopher Chedeau2aa23a871d92
diff --git a/.changeset/reset-hidden-until-found.md b/.changeset/reset-hidden-until-found.mdnew file mode 100644index 0000000000..6a8e338ea4--- /dev/null+++ b/.changeset/reset-hidden-until-found.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] `reset.css` no longer hides `hidden="until-found"` content with `display: none`. The browser's own rendering, `content-visibility: hidden`, now applies, so find in page and text fragment links can find the content and reveal it, as the HTML Standard specifies. Plain `hidden` elements are still `display: none`, and a browser without until-found support still hides the content with its own `[hidden]` rule.++@vjeuxdiff --git a/.github/pages/assets/manifest.json b/.github/pages/assets/manifest.jsonindex 51bcfa28da..e54fe84006 100644--- a/.github/pages/assets/manifest.json+++ b/.github/pages/assets/manifest.json@@ -6,7 +6,7 @@},"files": {"reset.css": {- "sha256": "b4d429b96882389b18b8df23086a686eda7c8427c66d5089c86969b2fc754323"+ "sha256": "8423107ecd6d1ea308d277ebc83fb5d6115ccddece700ce0f489ba44d42d8461"},"astryx.css": {"sha256": "bc66e60ffeb0eb3b2f2b303d89ba6bae1e7e922b10bb380f7b25624d73c765ba"diff --git a/.github/pages/assets/reset.css b/.github/pages/assets/reset.cssindex 19246aad50..845c4c32c5 100644--- a/.github/pages/assets/reset.css+++ b/.github/pages/assets/reset.css@@ -354,9 +354,11 @@}/*- * Ensure hidden elements are actually hidden.+ * Ensure hidden elements are actually hidden. `hidden="until-found"` keeps+ * the browser's own rendering, `content-visibility: hidden`, so find in page+ * and text fragment links can still find its content and reveal it.*/- :where([hidden]) {+ :where([hidden]:not([hidden='until-found' i])) {display: none;}diff --git a/packages/core/src/reset.css b/packages/core/src/reset.cssindex 19246aad50..845c4c32c5 100644--- a/packages/core/src/reset.css+++ b/packages/core/src/reset.css@@ -354,9 +354,11 @@}/*- * Ensure hidden elements are actually hidden.+ * Ensure hidden elements are actually hidden. `hidden="until-found"` keeps+ * the browser's own rendering, `content-visibility: hidden`, so find in page+ * and text fragment links can still find its content and reveal it.*/- :where([hidden]) {+ :where([hidden]:not([hidden='until-found' i])) {display: none;}diff --git a/packages/core/src/reset.until-found.a11y.browser.spec.ts b/packages/core/src/reset.until-found.a11y.browser.spec.tsnew file mode 100644index 0000000000..986af19cfe--- /dev/null+++ b/packages/core/src/reset.until-found.a11y.browser.spec.ts@@ -0,0 +1,75 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file reset.until-found.a11y.browser.spec.ts+ * @input packages/core/src/reset.css, alone on a blank page+ * @output Browser evidence that `hidden="until-found"` content stays findable+ * @position reset.css integration proof. The browser hides until-found content+ * with `content-visibility: hidden`, which find in page and text fragments+ * can search and reveal; `display: none` takes the content out of both, and+ * only a shipping engine shows which one applies.+ */++import * as fs from 'node:fs';+import {fileURLToPath} from 'node:url';+import {expect, test} from '@playwright/test';++const RESET_CSS = fs.readFileSync(+ fileURLToPath(new URL('./reset.css', import.meta.url)),+ 'utf8',+);++// Served at a real URL so a text fragment navigation can run against it.+const ORIGIN = 'http://reset.test';+const PAGE = `<!doctype html>+<style>${RESET_CSS}</style>+<div style="height: 3000px">Above the fold</div>+<div id="answer" hidden="until-found">The hidden answer</div>+<div id="closed" hidden>Plain hidden text</div>+<script>+ document.getElementById('answer').addEventListener('beforematch', () => {+ document.body.dataset.beforematch = 'fired';+ });+</script>`;++test.beforeEach(async ({page}) => {+ await page.route(`${ORIGIN}/**`, async route =>+ route.fulfill({contentType: 'text/html', body: PAGE}),+ );+});++test('until-found content keeps the browser rendering', async ({page}) => {+ await page.goto(`${ORIGIN}/`);+ const styles = await page.evaluate(() =>+ ['answer', 'closed'].map(id => {+ const element = document.getElementById(id);+ if (!element) {+ throw new Error(`missing #${id}`);+ }+ const style = getComputedStyle(element);+ return {+ display: style.display,+ contentVisibility: style.contentVisibility,+ };+ }),+ );+ expect(styles).toEqual([+ {display: 'block', contentVisibility: 'hidden'},+ {display: 'none', contentVisibility: 'visible'},+ ]);+});++test('a text fragment finds until-found content and reveals it', async ({+ page,+}) => {+ await page.goto(`${ORIGIN}/#:~:text=hidden%20answer`);+ // The browser removes the attribute and fires beforematch when it reveals.+ await expect(page.locator('#answer')).not.toHaveAttribute('hidden');+ await expect(page.locator('#answer')).toBeInViewport();+ await expect(page.locator('body')).toHaveAttribute(+ 'data-beforematch',+ 'fired',+ );+ // Plain hidden content stays out of reach.+ await expect(page.locator('#closed')).toBeHidden();+});diff --git a/packages/core/src/reset.until-found.test.ts b/packages/core/src/reset.until-found.test.tsnew file mode 100644index 0000000000..5b228ad004--- /dev/null+++ b/packages/core/src/reset.until-found.test.ts@@ -0,0 +1,32 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * Static guard for the reset's `[hidden]` rule and `hidden="until-found"`.+ *+ * The browser hides until-found content with `content-visibility: hidden`,+ * which find in page and text fragments can search and reveal. A+ * `display: none` that also matches it takes the content out of both.+ * reset.until-found.a11y.browser.spec.ts measures the result in a browser.+ */++import fs from 'fs';+import path from 'path';++import {describe, expect, it} from 'vitest';++describe('reset.css and hidden="until-found"', () => {+ it('sets display: none only on hidden elements that are not until-found', () => {+ const stripped = fs+ .readFileSync(path.resolve(__dirname, './reset.css'), 'utf-8')+ .replace(/\/\*[\s\S]*?\*\//g, '');+ const hiddenRules = [...stripped.matchAll(/([^{}]+)\{([^{}]*)\}/g)]+ .map(([, selector, body]) => ({selector: selector.trim(), body}))+ .filter(({selector}) => selector.includes('[hidden'));+ expect(hiddenRules.length).toBeGreaterThan(0);+ for (const {selector, body} of hiddenRules) {+ if (/display:\s*none/.test(body)) {+ expect(selector).toContain(":not([hidden='until-found' i])");+ }+ }+ });+});