fix: tab on current input field to focus the next input field (#3754)
This commit is contained in:
@@ -37,7 +37,7 @@
|
|||||||
v-if="currentSuggestionIndex === index"
|
v-if="currentSuggestionIndex === index"
|
||||||
class="hidden items-center text-secondary md:flex"
|
class="hidden items-center text-secondary md:flex"
|
||||||
>
|
>
|
||||||
<kbd class="shortcut-key">TAB</kbd>
|
<kbd class="shortcut-key">Enter</kbd>
|
||||||
<span class="ml-2 truncate">to select</span>
|
<span class="ml-2 truncate">to select</span>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
@@ -169,22 +169,18 @@ watch(
|
|||||||
)
|
)
|
||||||
|
|
||||||
const handleKeystroke = (ev: KeyboardEvent) => {
|
const handleKeystroke = (ev: KeyboardEvent) => {
|
||||||
if (["ArrowDown", "ArrowUp", "Enter", "Tab", "Escape"].includes(ev.key)) {
|
if (!props.autoCompleteSource) return
|
||||||
|
|
||||||
|
if (["ArrowDown", "ArrowUp", "Enter", "Escape"].includes(ev.key)) {
|
||||||
ev.preventDefault()
|
ev.preventDefault()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ev.shiftKey) {
|
if (["Escape", "Tab", "Shift"].includes(ev.key)) {
|
||||||
showSuggestionPopover.value = false
|
showSuggestionPopover.value = false
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
showSuggestionPopover.value = true
|
if (ev.key === "Enter") {
|
||||||
|
if (suggestions.value.length > 0 && currentSuggestionIndex.value > -1) {
|
||||||
if (
|
|
||||||
["Enter", "Tab"].includes(ev.key) &&
|
|
||||||
suggestions.value.length > 0 &&
|
|
||||||
currentSuggestionIndex.value > -1
|
|
||||||
) {
|
|
||||||
updateModelValue(suggestions.value[currentSuggestionIndex.value])
|
updateModelValue(suggestions.value[currentSuggestionIndex.value])
|
||||||
currentSuggestionIndex.value = -1
|
currentSuggestionIndex.value = -1
|
||||||
|
|
||||||
@@ -201,6 +197,15 @@ const handleKeystroke = (ev: KeyboardEvent) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (showSuggestionPopover.value) {
|
||||||
|
showSuggestionPopover.value = false
|
||||||
|
} else {
|
||||||
|
emit("enter", ev)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
showSuggestionPopover.value = true
|
||||||
|
}
|
||||||
|
|
||||||
if (ev.key === "ArrowDown") {
|
if (ev.key === "ArrowDown") {
|
||||||
scrollActiveElIntoView()
|
scrollActiveElIntoView()
|
||||||
|
|
||||||
@@ -223,15 +228,6 @@ const handleKeystroke = (ev: KeyboardEvent) => {
|
|||||||
emit("keyup", ev)
|
emit("keyup", ev)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ev.key === "Enter") {
|
|
||||||
emit("enter", ev)
|
|
||||||
showSuggestionPopover.value = false
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ev.key === "Escape") {
|
|
||||||
showSuggestionPopover.value = false
|
|
||||||
}
|
|
||||||
|
|
||||||
// used to scroll to the first suggestion when left arrow is pressed
|
// used to scroll to the first suggestion when left arrow is pressed
|
||||||
if (ev.key === "ArrowLeft") {
|
if (ev.key === "ArrowLeft") {
|
||||||
if (suggestions.value.length > 0) {
|
if (suggestions.value.length > 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user