From 81f48eab83952858aacb31450e40bd73f24673da Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Thu, 27 Sep 2018 17:15:12 +0530 Subject: [PATCH] Fix keyboard navigation in Autocomplete --- ui/components/controls/Autocomplete.vue | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ui/components/controls/Autocomplete.vue b/ui/components/controls/Autocomplete.vue index 4d01fe7e..cbde38b7 100644 --- a/ui/components/controls/Autocomplete.vue +++ b/ui/components/controls/Autocomplete.vue @@ -22,11 +22,11 @@ export default { keydown: e => { if (e.keyCode === 38) { // up - this.highlightedItem -= 1; + this.highlightAboveItem(); } if (e.keyCode === 40) { // down - this.highlightedItem += 1; + this.highlightBelowItem(); } if (e.keyCode === 13) { if (this.highlightedItem > -1) { @@ -45,6 +45,18 @@ export default { } } }, + highlightBelowItem() { + this.highlightedItem += 1; + if (this.highlightedItem > this.popupItems.length - 1) { + this.highlightedItem = this.popupItems.length - 1; + } + }, + highlightAboveItem() { + this.highlightedItem -= 1; + if (this.highlightedItem < 0) { + this.highlightedItem = 0; + } + }, getChildrenElement(h) { return [ this.onlyInput ? null : this.getLabelElement(h),