Fix: pressing enter would ignore input

This commit is contained in:
Pieter Vander Vennet 2024-01-12 23:27:01 +01:00
parent 8f036f6045
commit 95c41d672e
2 changed files with 15 additions and 2 deletions

View file

@ -51,6 +51,15 @@
} }
} }
function onKeyPress(e: KeyboardEvent){
if(e.key === "Enter"){
e.stopPropagation()
e.preventDefault()
dispatch("submit")
}
}
initValueAndDenom() initValueAndDenom()
$: { $: {
@ -126,7 +135,7 @@
let htmlElem: HTMLInputElement | HTMLTextAreaElement let htmlElem: HTMLInputElement | HTMLTextAreaElement
let dispatch = createEventDispatcher<{ selected }>() let dispatch = createEventDispatcher<{ selected, submit }>()
$: { $: {
if (htmlElem !== undefined) { if (htmlElem !== undefined) {
htmlElem.onfocus = () => dispatch("selected") htmlElem.onfocus = () => dispatch("selected")
@ -144,6 +153,7 @@
inputmode={validator?.inputmode ?? "text"} inputmode={validator?.inputmode ?? "text"}
placeholder={_placeholder} placeholder={_placeholder}
bind:this={htmlElem} bind:this={htmlElem}
on:keypress={onKeyPress}
/> />
{:else} {:else}
<div class={twMerge("inline-flex", cls)}> <div class={twMerge("inline-flex", cls)}>
@ -153,6 +163,7 @@
class="w-full" class="w-full"
inputmode={validator?.inputmode ?? "text"} inputmode={validator?.inputmode ?? "text"}
placeholder={_placeholder} placeholder={_placeholder}
on:keypress={onKeyPress}
/> />
{#if !$isValid} {#if !$isValid}
<ExclamationIcon class="-ml-6 h-6 w-6" /> <ExclamationIcon class="-ml-6 h-6 w-6" />

View file

@ -198,7 +198,9 @@
function onInputKeypress(e: KeyboardEvent) { function onInputKeypress(e: KeyboardEvent) {
if (e.key === "Enter") { if (e.key === "Enter") {
onSave() e.preventDefault()
e.stopPropagation()
onSave(e)
} }
} }