Repository navigation
fix(nav): focus the section after a cross-route nav tap - #275
Merged
Merged
Conversation
Closes #274 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Deploying website with
|
| Latest commit: |
4a719c4
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://bed5feb1.website-70y.pages.dev |
| Branch Preview URL: | https://claude-cross-route-section-f.website-70y.pages.dev |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Closes #274
Why
Tapping a section on
/moves keyboard and screen-reader focus into it. Tapping one from/blog/*or/legal/*didn't. The viewport landed on the section, but the next Tab started from the top of the nav:router.push, and focus went back to the hamburger.<Link>, and focus stayed on the clicked link.Next's hash scroll doesn't move focus at all. Next 16.3.8 defaults
experimental.appNewScrollHandlertotrue, and that handler (InnerScrollHandlerNewinlayout-router.js) intentionally leaves focus untouched. (The issue assumed Next callsdomNode.focus(); only the legacy handler does that.)What changed
lib/scroll.tsadds three helpers:focusSection(el)holds the focus rule both navs already inlined: addtabindex="-1"only if the element isn't already focusable, and focus withpreventScroll: true.queueSectionFocus(id)andtakeSectionFocus(hash)form a single-use, module-level queue.takeSectionFocusreturns the id only when the URL actually landed on#id, so a stale id left by an abandoned nav can't focus a section on a later home arrival.Chrome.tsx:<Link>.pathnamefocuses the queued section once home has committed. It is a passive effect, so it runs after Next's hash scroll, which runs in the layout phase.focusSection.MobileMenu.tsx:focusMovedToSectionRef, so the toggle-refocus effect doesn't take focus back.focusSection.lib/scroll.test.tsadds unit tests for both helpers, using fake elements, so no DOM env is needed. They cover:focus()preventScrollVerification
pnpm test,pnpm typecheck,pnpm lint,pnpm format:checkandpnpm build(includingcheck:outandcheck:og-image) all pass./blog/,/blog/what-were-building/and/legal/privacy/:document.activeElementis the section and the URL has one hash. Once the scroll settles the section is at the viewport top, and the next Tab reaches the first focusable element inside#faq.#methodhas no focusable children, so Tab correctly continues to the next tab stop after it./with no hash. In the drawer, focus is on.mm-toggle;#intronever gets focus./: unchanged. The same-page desktop path only switched to the shared helper and wasn't clicked through in the browser.🤖 Generated with Claude Code