Beautiful Open-Source Form Builder
Enhance VSelect component to maintain scroll position during virtuali… (#967)
Chirag Chhatrala3f357e43b23b
diff --git a/client/components/forms/core/components/VSelect.vue b/client/components/forms/core/components/VSelect.vueindex e14346e41..9d88d5b96 100644--- a/client/components/forms/core/components/VSelect.vue+++ b/client/components/forms/core/components/VSelect.vue@@ -534,23 +534,32 @@ export default {}},setupVirtualizer () {- if (!this.$refs.scrollRef || !this.filteredOptions || this.filteredOptions.length === 0) {+ const scrollEl = this.$refs.scrollRef+ const previousScrollTop = scrollEl?.scrollTop ?? null++ // Restore scroll position after DOM updates (prevents jump on multi-select)+ const restoreScroll = () => {+ if (previousScrollTop === null) return+ this.$nextTick(() => {+ if (this.$refs.scrollRef) {+ this.$refs.scrollRef.scrollTop = previousScrollTop+ }+ })+ }++ if (!scrollEl || !this.filteredOptions?.length) {this.virtualizer = nullreturn}// Clean up existing virtualizer- if (this.virtualizer) {- this.virtualizer = null- }+ this.virtualizer = null// Skip virtualization if list fits in visible height- const dropdownEl = this.$refs.scrollRef- const maxVisibleHeight = dropdownEl && dropdownEl.clientHeight ? dropdownEl.clientHeight : 0- const estimatedItemSize = this.estimatedItemSizePx- const estimatedTotal = this.filteredOptions.length * estimatedItemSize+ const maxVisibleHeight = scrollEl.clientHeight || 0+ const estimatedTotal = this.filteredOptions.length * this.estimatedItemSizePxif (maxVisibleHeight && estimatedTotal <= maxVisibleHeight) {- this.virtualizer = null+ restoreScroll()return}@@ -559,9 +568,10 @@ export default {getScrollElement: () => this.$refs.scrollRef,estimateSize: () => this.estimatedItemSizePx,overscan: 5,- // Dynamic measurement so item height adapts to content- measureElement: (el) => (el ? el.getBoundingClientRect().height : 0)+ measureElement: (el) => el?.getBoundingClientRect().height ?? 0})++ restoreScroll()},isSelected (value) {if (!this.modelValue) return false