git clone git@github.com:lukaszpolowczyk/focus-button.git
cd focus-button
npm run dev
Open url: [http://localhost:3000/1]
- Refresh page
- Press
Tab key
on the keyboard - The button are focused
- Press
Right Arrow
on the keyboard - The button loses focus
Question: How do I keep focus without using element.focus()
or anything like that?
GIF with this:
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 />