question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sveltekit:keepfocus

See original GitHub issue

Is your feature request related to a problem? Please describe.

  1. Refresh page
  2. Press Tab key on the keyboard
  3. The button are focused
  4. Press Right Arrow on the keyboard
  5. The button loses focus

GIF with this: lost-focus

Describe the solution you’d like Maybe similar to sveltekit:noscroll and goto(href, { replaceState, noscroll }) , e.g. sveltekit:keepfocus and goto(href, { replaceState, keepfocus })?

It looks like something easy to do. L245 of router.js would have to give in a similar condition as L254 of router.js.

Describe alternatives you’ve considered Described by @ahtcx in https://github.com/sveltejs/kit/issues/968#issuecomment-817378602

as a workaround I’ve been using patch-package on L245 of router.js but this isn’t ideal and I imagine router.js will change a lot so you’ll have to update it at every change.

How important is this feature to you? Using the keyboard and keeping the application focused is a matter of accessibility in general.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:19 (15 by maintainers)

github_iconTop GitHub Comments

5reactions
ahtcxcommented, Apr 16, 2021

My use case for this would be within the goto function. I have a search page /search/[searchQuery] which I would like to update on user input. (for an example, see Spotify’s web client)

The issue is that on input change, focus is lost from the text input. There are possible workarounds but they’re a pain and not very clean.

I think that it’s a nice option to have, as it allows more flexibility with the router with very little overhead.

4reactions
MatthiasGrandlcommented, Jun 4, 2021

I have the same issue. I am implementing a search with query parameters and it’s supposed to fetch filtered content live from the load function. So goto definitely makes sense here in my opinion…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Accessibility • Docs • SvelteKit
Keep in mind that while SvelteKit provides an accessible foundation, you are still responsible for making sure your application code is accessible.
Read more >
setFocus • REPL • Svelte
Interactive Svelte playground.
Read more >
Modules • Docs • SvelteKit
If `true`, the currently focused element will retain focus after navigation. Otherwise, focus will be reset to the body. */. keepFocus?: boolean;.
Read more >
Focus on mount • REPL • Svelte
import { onMount } from 'svelte'. 5. let usernameInput. 6. // this works here, but not in Sapper: 7. onMount(() => usernameInput.focus()). 8....
Read more >
Form actions • Docs • SvelteKit
... object // `action` is the URL to which the form is posted // `cancel()` will prevent the submission return async ... In...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found