From c63897f88865a241994d6021115eca98fae5f220 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Tue, 3 Dec 2019 13:51:50 +0530 Subject: [PATCH] fix(Dropdown): Natural keyboard navigation --- src/components/Dropdown.vue | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/components/Dropdown.vue b/src/components/Dropdown.vue index 07620316..5e56c94c 100644 --- a/src/components/Dropdown.vue +++ b/src/components/Dropdown.vue @@ -147,8 +147,7 @@ export default { if (index !== 0) { index -= 1; } - let highlightedElement = this.$refs.items[index]; - highlightedElement && highlightedElement.scrollIntoView(); + this.scrollToHighlighted(); }); }, highlightItemDown() { @@ -158,10 +157,13 @@ export default { } this.$nextTick(() => { - let index = this.highlightedIndex; - let highlightedElement = this.$refs.items[index]; - highlightedElement && highlightedElement.scrollIntoView(); + this.scrollToHighlighted(); }); + }, + scrollToHighlighted() { + let highlightedElement = this.$refs.items[this.highlightedIndex]; + highlightedElement && + highlightedElement.scrollIntoView({ block: 'nearest' }); } } };