Repository navigation
fix: limit the j and k step keys to focus inside the guide - #2
Merged
Merged
Conversation
The step keys listened on the whole document, so `j` or `k` changed the step from anywhere on the page except a text field. WCAG 2.1.4, Character Key Shortcuts, requires that the reader can turn off or remap a single-letter shortcut, or that the shortcut works only while its component has focus. The listener now sits on the guide's `main` element, which holds both panes. A keydown fires on the focused element, so the keys work only while focus is inside the guide, such as on a step's header, a Reviewed checkbox, or a link in the explanation. The scope is `main` rather than the steps pane because the narrow layout moves each explanation into its step. With `main`, the keys behave the same in both layouts. Right after a guide loads, focus is on the page itself, so a reader tabs into the guide or clicks a step before `j` and `k` work. The step navigation specs now focus the guide before they press a key, and new specs cover focus outside the guide and in the explanation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the change restricting the guide’s keyboard shortcuts to focus within its main element.
No open issues 🎉
What changed in this PR
This PR scopes the guide’s j and k step shortcuts to focus inside its main element, addressing WCAG 2.1.4 without adding settings or changing behavior across layouts.
Changes:
- Moves the keyboard listener from
documentto the guide’smain, preserving existing input and modifier guards. - Updates keyboard tests to focus the guide explicitly and adds coverage for focus outside the guide and within the explanation pane.
| File | Description |
|---|---|
tests/e2e/step-navigation.spec.ts |
Updates focus setup and verifies shortcut scope and focus movement. |
src/client/step-keys.ts |
Restricts shortcuts to the guide and documents the focus requirement. |
Review effort: Balanced
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
Copilot's last review of #1 flagged the
jandkstep keys. They listened on the whole document, so either letter changed the step from anywhere on the page except a text field. WCAG 2.1.4, Character Key Shortcuts, requires that the reader can turn off or remap a single-letter shortcut, or that the shortcut works only while its component has focus. This PR takes the focus option, because it needs no new setting or UI.What changes
initStepKeysinsrc/client/step-keys.tsnow listens on the guide'smainelement instead ofdocument. A keydown fires on the focused element, so the listener receivesjandkonly while focus is inside the guide, such as on a step's header, a Reviewed checkbox, or a link in the explanation. The guards for text fields and modifier keys stay as they were.The scope is
mainrather than the steps pane because the narrow layout moves each explanation into its step. Withmain, the keys behave the same in both layouts.Behavior change
Right after a guide loads, focus is on the page itself, so
jdoes nothing until the reader tabs into the guide or clicks a step. A reader who opened#step-2and pressedjused to reach step 3. Now they click or tab into the guide first.Tests
The key specs in
tests/e2e/step-navigation.spec.tsnow focus the guide before they press a key. New specs check that the keys do nothing with focus on the page or on the breadcrumb, and that they work from a link in the explanation pane. The spec for focus outside the guide fails against the old listener.pnpm checkpasses, andpnpm testpasses all 73 specs.🤖 Generated with Claude Code