Add a way to manually restore focus and scroll to hash element
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 2.3k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 156
Description
Describe the problem
Sveltekit's router handles very well the focus and hash navigation, but it would be nice to be able to handle this manually sometimes using the same logic as the router.
Use case:
We have a page transition system at the agency where I work that delays the <slot> rendering in +layout.svelte until after the transition animation finishes (on outroend). All the router's focus and hash related code has already run by then, so we have to replicate that logic ourselves and run it after this animation to keep the navigation functioning properly.
Describe the proposed solution
Expose this logic in functions (or a single function that does both) that we can import (I don't really have any great ideas for naming right now).
import { restoreFocus, restoreHash } from '$app/navigation';
Alternatives considered
Replicate this logic in our own code.
Importance
would make my life easier
Additional Information
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating SvelteKit's router focus and hash-navigation logic and the $app/navigation entry point. Expose that existing behavior for manual use after delayed +layout.svelte slot rendering, and verify that focus restoration and hash scrolling still work after the transition.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100