From 6a5da5cf52a295a441ef32762d913759d1e730e1 Mon Sep 17 00:00:00 2001 From: andrewwallacespeckle Date: Thu, 11 Sep 2025 17:23:37 +0100 Subject: [PATCH] Scroll to value on addition --- .../filters/filter/string/Checkboxes.vue | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/packages/frontend-2/components/viewer/filters/filter/string/Checkboxes.vue b/packages/frontend-2/components/viewer/filters/filter/string/Checkboxes.vue index 7bcf7c234..232cfc0af 100644 --- a/packages/frontend-2/components/viewer/filters/filter/string/Checkboxes.vue +++ b/packages/frontend-2/components/viewer/filters/filter/string/Checkboxes.vue @@ -50,6 +50,7 @@ const sortMode = defineModel('sortMode', { default: SortMode.Alphabetical }) +const previousLength = ref(0) const itemHeight = 28 const maxHeight = 240 @@ -65,8 +66,31 @@ const filteredValues = computed(() => { }) }) -const { list, containerProps, wrapperProps } = useVirtualList(filteredValues, { - itemHeight, - overscan: 5 -}) +const { list, containerProps, wrapperProps, scrollTo } = useVirtualList( + filteredValues, + { + itemHeight, + overscan: 10 + } +) + +// Scroll to newly added values +watch( + () => props.filter.selectedValues, + (newValues) => { + if (newValues.length > previousLength.value) { + // Find the newly added value + const newValue = newValues[newValues.length - 1] + const index = filteredValues.value.findIndex((v) => v === newValue) + if (index !== -1) { + nextTick(() => { + const scrollIndex = Math.max(0, index - 3) // Center-ish position + scrollTo(scrollIndex) + }) + } + } + previousLength.value = newValues.length + }, + { immediate: true } +)