Focus next element on Enter

This commit is contained in:
Jan Bader 2022-02-09 21:56:59 +00:00
parent c3a1564c4e
commit 3bd5845068

View File

@ -56,6 +56,12 @@ export default defineComponent({
if(e.key == "Enter") { if(e.key == "Enter") {
const selected = this.$data.Suggestions[0]; const selected = this.$data.Suggestions[0];
this.selectElement(selected); this.selectElement(selected);
const el = (<HTMLInputElement>e.target);
const inputElements = Array.from(el.ownerDocument.querySelectorAll('input:not([disabled]):not([readonly])'));
const currentIndex = inputElements.indexOf(el);
const nextElement = inputElements[currentIndex < inputElements.length - 1 ? currentIndex + 1 : 0];
(<HTMLInputElement>nextElement).focus();
} }
}, },
selectElement(element : Suggestion) { selectElement(element : Suggestion) {