Skip to content

Commit

Permalink
fix: click outside to hide autocompleted servers
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Jan 1, 2023
1 parent 727d059 commit ca1b716
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion components/user/UserSignIn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ function onEnter(e: KeyboardEvent) {
}
}
function escapeAutocomplete(evt: KeyboardEvent) {
if (!autocompleteShow)
return
autocompleteShow = false
evt.stopPropagation()
}
function select(index: number) {
server = filteredServers[index]
}
Expand All @@ -87,6 +94,10 @@ onMounted(async () => {
knownServers = await $fetch('/api/list-servers')
fuse = new Fuse(knownServers, { shouldSort: true })
})
onClickOutside($$(input), () => {
autocompleteShow = false
})
</script>

<template>
Expand Down Expand Up @@ -123,7 +134,7 @@ onMounted(async () => {
@keydown.down="move(1)"
@keydown.up="move(-1)"
@keydown.enter="onEnter"
@keydown.esc.prevent="autocompleteShow = false"
@keydown.esc.prevent="escapeAutocomplete"
@focus="autocompleteShow = true"
>
<div
Expand Down

0 comments on commit ca1b716

Please sign in to comment.