Skip to content
This repository has been archived by the owner on Jun 11, 2022. It is now read-only.

An example of losing focus with sveltekit routing

Notifications You must be signed in to change notification settings

lukaszpolowczyk/focus-button

Repository files navigation

focus-button

Run

git clone git@github.com:lukaszpolowczyk/focus-button.git
cd focus-button
npm run dev

Open url: [http://localhost:3000/1]

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 />

About

An example of losing focus with sveltekit routing

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published