src/routes/NewTask.svelte (view raw)
1<script lang="ts">
2 import { db } from '$lib/db';
3
4 const onKeyDown = (e: KeyboardEvent) => {
5 const element = e.target as HTMLInputElement;
6 const inputValue = element?.value;
7 if (e.code === 'Enter' && inputValue) {
8 db.tasks.add({ content: inputValue });
9 element.value = '';
10 }
11 };
12</script>
13
14<input
15 class="input input-bordered w-full"
16 type="text"
17 placeholder="Ajouter une tâche"
18 onkeydown={onKeyDown}
19/>