sveltejs / sveltejs/kit

Add a way to manually restore focus and scroll to hash element

Open
#7,752 3 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.