Correctly blocks arrow up/down on input

This commit is contained in:
Simon Cambier
2022-04-28 20:44:06 +02:00
parent d74b9cda5b
commit 8caeaaf66e

View File

@@ -2,7 +2,7 @@
import { debounce } from "obsidian" import { debounce } from "obsidian"
import { createEventDispatcher, onMount, tick } from "svelte" import { createEventDispatcher, onMount, tick } from "svelte"
export let value = '' export let value = ""
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
let elInput: HTMLInputElement let elInput: HTMLInputElement
@@ -13,6 +13,14 @@ onMount(async () => {
elInput.select() elInput.select()
}) })
function onKeydown(e: KeyboardEvent) {
switch (e.key) {
case "ArrowUp":
case "ArrowDown":
e.preventDefault()
}
}
const debouncedOnInput = debounce(() => { const debouncedOnInput = debounce(() => {
dispatch("input", value) dispatch("input", value)
}, 100) }, 100)
@@ -22,6 +30,7 @@ const debouncedOnInput = debounce(() => {
bind:value bind:value
bind:this={elInput} bind:this={elInput}
on:input={debouncedOnInput} on:input={debouncedOnInput}
on:keydown={onKeydown}
type="text" type="text"
class="prompt-input" class="prompt-input"
placeholder="Type to search through your notes" placeholder="Type to search through your notes"