Repository navigation
Keep keyboard focus visible below the mobile stage #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jay23606
wants to merge
9
commits into
codekongdev:main
Choose a base branch
from
jay23606:pr-go/14-plz-3d-explain-keep-keyboard-focus-visib
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
31c4ab1
Keep keyboard focus visible below the mobile stage
jay23606 5cf2981
fix(plz-3d-explain): make code examples keyboard-focusable
jay23606 1983d99
fix(plz-3d-explain): name code regions distinctly
jay23606 1649c83
Address review feedback
jay23606 9e7c45f
Merge remote-tracking branch 'upstream/main' into pr-30-fixes
jay23606 123b6a6
fix: reset mobile focus offset when stage fails
jay23606 d695431
fix: preserve reading position when stage controls focus
jay23606 74e753f
test: cover mobile focus and scroll behavior
jay23606 df5d379
test: require exact zero scroll padding
jay23606 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import { readFile } from 'node:fs/promises'; | ||
| import { dirname, join } from 'node:path'; | ||
| import { test } from 'node:test'; | ||
| import { fileURLToPath } from 'node:url'; | ||
|
|
||
| const assets = join(dirname(fileURLToPath(import.meta.url)), '..', 'skills', 'plz-3d-explain', 'assets'); | ||
| const pages = ['template.html', 'example-agent-sandbox.html', 'example-agent-sandbox.en.html']; | ||
| const stackedQuery = '@media (max-width: 860px) and (orientation: portrait)'; | ||
|
|
||
| // Remove CSS comments so a rule quoted inside a comment cannot satisfy a check. | ||
| const stripComments = (css) => css.replace(/\/\*[\s\S]*?\*\//g, ''); | ||
|
|
||
| // Return the text inside the braces of the first at-rule whose prelude starts with `prelude`. | ||
| function blockBody(css, prelude) { | ||
| const start = css.indexOf(prelude); | ||
| if (start === -1) return null; | ||
| const open = css.indexOf('{', start); | ||
| let depth = 0; | ||
| for (let i = open; i < css.length; i++) { | ||
| if (css[i] === '{') depth++; | ||
| if (css[i] === '}' && --depth === 0) return css.slice(open + 1, i); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| for (const page of pages) { | ||
| test(`stacked stage reserves scroll padding and code blocks show focus in ${page}`, async () => { | ||
| const css = stripComments(await readFile(join(assets, page), 'utf8')); | ||
| const stacked = blockBody(css, stackedQuery); | ||
| assert.ok(stacked, `missing ${stackedQuery} block in ${page}`); | ||
| assert.match( | ||
| stacked, | ||
| /(?:^|[\s,}])html\s*\{[^}]*scroll-padding-top:\s*var\(--stage-h\)/, | ||
| `missing html scroll-padding-top: var(--stage-h) inside the stacked media query in ${page}`, | ||
| ); | ||
| assert.match( | ||
| stacked, | ||
| /html:has\(\.stage \.autorun:focus,\s*\.stage \.reset-view:focus\)\s*\{[^}]*scroll-padding-top:\s*0(?:[a-z%]+)?(?:\s*!important)?\s*;/, | ||
| `focused stage controls should not shift the reading area in ${page}`, | ||
| ); | ||
| assert.doesNotMatch(stacked, /(?:^|[\s,}])(?:\.chapter|\[data-scene\])\s*\{[^}]*scroll-margin-top:\s*var\(--stage-h\)/, `stacked chapter scroll margin duplicates root padding in ${page}`); | ||
| assert.match( | ||
| css, | ||
| /html:has\(\.stage\[data-state="failed"\],\s*\.stage\.no-webgl\)\s*\{[^}]*scroll-padding-top:\s*0(?:[a-z%]+)?(?:\s*!important)?\s*;/, | ||
| `missing exact-zero failed-stage scroll padding reset in ${page}`, | ||
| ); | ||
| assert.doesNotMatch( | ||
| "scroll-padding-top: 0.5rem;", | ||
| /scroll-padding-top:\s*0(?:[a-z%]+)?(?:\s*!important)?\s*;/, | ||
| "a nonzero decimal must not satisfy an exact-zero reset", | ||
| ); | ||
| assert.match( | ||
| css, | ||
| /(?:^|[\s,}])pre\.code:focus-visible\s*\{[^}]*outline:\s*3px\s+solid\s+var\(--bound\)\s*;/, | ||
| `missing visible 3px solid var(--bound) pre.code:focus-visible outline in ${page}`, | ||
| ); | ||
| if (page !== 'template.html') { | ||
| const markup = await readFile(join(assets, page), 'utf8'); | ||
| const codeBlocks = [...markup.matchAll(/<pre class="code"([^>]*)>/g)]; | ||
| assert.ok(codeBlocks.length > 0, `missing code blocks in ${page}`); | ||
| const labels = []; | ||
| for (const [, attributes] of codeBlocks) { | ||
| assert.match(attributes, /\btabindex="0"/, `code block is not keyboard-focusable in ${page}`); | ||
| assert.match(attributes, /\brole="region"/, `code block is missing region semantics in ${page}`); | ||
| const label = attributes.match(/\baria-label="([^"]+)"/); | ||
| assert.ok(label, `code block is missing an accessible name in ${page}`); | ||
| labels.push(label[1]); | ||
| } | ||
| assert.equal(new Set(labels).size, labels.length, `code block names must be distinct in ${page}`); | ||
| } | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.