Skip to content

Navigation API router: do not reset focus on navigation#152

Merged
rschristian merged 1 commit into
preactjs:mainfrom
AFCMS:navigation_focus_fix
Jul 2, 2026
Merged

Navigation API router: do not reset focus on navigation#152
rschristian merged 1 commit into
preactjs:mainfrom
AFCMS:navigation_focus_fix

Conversation

@AFCMS

@AFCMS AFCMS commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Fixes #151

The fix have been tested in my own projects.

I have added a test case which verifies if focus is preserved.

rschristian
rschristian previously approved these changes Jun 30, 2026

@rschristian rschristian left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks!

Unfortunately won't be able to release for a bit as I'm on vacation, will do when I get back

@rschristian
rschristian dismissed their stale review June 30, 2026 11:10

Actually, I want to think about this more. I can also imagine a header search bar which navigates to a new page, at which point, maintaining focus by default would be less than ideal. Hmm

@AFCMS

AFCMS commented Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

Is there a way to prevent focus change with the main router implementation at the moment? I understand it would be better to leave the user the choice of the focus behavior.

@rschristian

rschristian commented Jun 30, 2026

Copy link
Copy Markdown
Member

Sorry, do you mean "allow focus change" (or blur)? To my knowledge, the main router will not blur, though I don't think we have any tests guaranteeing behavior.

It's also a bit moot as the Navigation API is the future, what the previous iteration does shouldn't constrain us as this is opt-in yet.


I believe the current solution here is still fine, users can manually blur if they need to much easier than re-focusing, but want to think on it longer. Navigation API defaults to MPA-like behavior intentionally, maybe it'll be better to match yet. Not sure.

@rschristian rschristian left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought on it more and I think this will indeed be the better path.

Sorry for the switch up & delay! Just had to think things through a bit.

@rschristian
rschristian merged commit 37e84db into preactjs:main Jul 2, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Behavior mismatch between the Navigation API router and the original one

2 participants