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