From 2be35b0d4f20586a52d049d75ab659c4c5f7c269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tu=C4=9F=C3=A7e=20K=C3=BC=C3=A7=C3=BCko=C4=9Flu?= Date: Tue, 28 Sep 2021 16:39:46 +0300 Subject: [PATCH] Fixed #1535 - Dropdown v2 doesn't scroll when navigating with keyboard --- src/components/dropdown/Dropdown.vue | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/components/dropdown/Dropdown.vue b/src/components/dropdown/Dropdown.vue index 8d99d3452c..b27f36e11c 100755 --- a/src/components/dropdown/Dropdown.vue +++ b/src/components/dropdown/Dropdown.vue @@ -85,6 +85,11 @@ export default { overlayVisible: false }; }, + watch: { + value() { + this.isModelValueChanged = true; + } + }, outsideClickListener: null, scrollHandler: null, resizeListener: null, @@ -92,7 +97,13 @@ export default { currentSearchChar: null, previousSearchChar: null, searchValue: null, + isValueChanged: false, updated() { + if (this.overlayVisible && this.isModelValueChanged) { + this.scrollValueInView(); + } + this.isModelValueChanged = false; + this.onFilterUpdated(); }, beforeDestroy() { @@ -465,7 +476,15 @@ export default { if (this.overlayVisible) { this.alignOverlay(); } - } + }, + scrollValueInView() { + if (this.$refs.overlay) { + let selectedItem = DomHandler.findSingle(this.$refs.overlay, 'li.p-highlight'); + if (selectedItem) { + selectedItem.scrollIntoView({ block: 'nearest', inline: 'start' }); + } + } + }, }, computed: { visibleOptions() {