fix: chord page auto-focuses input on first load

fixes #111
This commit is contained in:
2024-04-23 17:46:05 +02:00
parent 19cf0b26b3
commit 8b2bc6d109

View File

@@ -1,5 +1,5 @@
<script lang="ts"> <script lang="ts">
import { tick } from "svelte"; import { onMount, tick } from "svelte";
import { changes, ChangeType } from "$lib/undo-redo"; import { changes, ChangeType } from "$lib/undo-redo";
import type { ChordInfo } from "$lib/undo-redo"; import type { ChordInfo } from "$lib/undo-redo";
import { scale } from "svelte/transition"; import { scale } from "svelte/transition";
@@ -11,6 +11,12 @@
export let chord: ChordInfo; export let chord: ChordInfo;
onMount(() => {
if (chord.phrase.length === 0) {
box.focus();
}
});
function keypress(event: KeyboardEvent) { function keypress(event: KeyboardEvent) {
if (event.key === "ArrowUp") { if (event.key === "ArrowUp") {
addSpecial(event); addSpecial(event);
@@ -103,7 +109,6 @@
<div <div
on:keydown={keypress} on:keydown={keypress}
on:mousedown={clickCursor} on:mousedown={clickCursor}
autofocus={chord.phrase.length === 0}
role="textbox" role="textbox"
tabindex="0" tabindex="0"
bind:this={box} bind:this={box}