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.

The button loses focus from the button when moving to the next subpages

See original GitHub issue

The button loses focus from the button when moving to the next subpages: Example (with a description of the problem): https://github.com/lukaszpolowczyk/focus-button

Problem

  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

Question: How do I keep focus without using element.focus() or anything like that?

GIF with this: lost-focus

The code looks like this:

<!-- src/routers/[slug].svelte -->
<svelte:head><title>Lost focus - Sveltekit Routers</title></svelte:head>
<script>
  import { page } from '$app/stores';
  
</script>
<br>
page {$page.params.slug}

<!-- src/routers/$layout.svelte -->
<script>
  import { page } from '$app/stores';
  import { goto } from '$app/navigation';
  
  import Keydown from "svelte-keydown";
</script>
<Keydown on:ArrowRight={() => goto(`${Number($page.params.slug)+1}`) } />

<button on:click={()=>goto(`${Number($page.params.slug)+1}`)}>goto({Number($page.params.slug)+1})</button>
or press RightArrow
<slot />

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
dummdidummcommented, Apr 11, 2021

GitHub issues are reserved for bug reports or feature requests. Please ask usage questions on StackOverflow or the Discord server.

By default a page change will not keep the element focused, that’s an accessibility best practice default. You’ll need to handle that yourself.

1reaction
lukaszpolowczykcommented, Apr 12, 2021

@dummdidumm @ahtcx I want it too. 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Click on a button that is moved when an input loses focus is ...
When the input is focused and the user tries to click the button, it loses the focus which may cause the hint to...
Read more >
Create and manage pages – Figma Help Center
Get in the habit of moving new components to the dedicated page. ... Click New project in the menu bar: Image showing the...
Read more >
51580 (Application Passwords: Accessibility Improvements)
There is a focus loss when clicking the "Revoke" button though. The button gets removed together with the table row and focus is...
Read more >
A Beginner's Guide to Notion (2022 Update) - The Sweet Setup
You can create pages in a variety of ways in Notion — you can click the + button beside your workspace in the...
Read more >
PowerPoint Tips: The Magical Reset Button | Stinson Design
Move content, change fonts, add colors. ... Any change you make to the placeholder boxes can be reset. Just remember that if you...
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