Skip to content

Commit da554f4

Browse files
jasonvargaclaude
andcommitted
delegate scroll-to-selected to reka's highlightSelected
The manual scroll math in scrollToSelectedOption was redundant and slightly wrong: Reka's highlightSelected() already triggers virtualFocusHook, which calls virtualizer.scrollToIndex(index) on the underlying TanStack virtualizer. The manual block was running on top of that, second-guessing it with a hardcoded estimatedItemHeight of 40px. That estimate matched the virtualizer's :estimate-size, but real items vary by size variant (xs items render closer to ~28px, xl closer to ~48px) and by custom slot content, so the "centered" position drifted off-center. Worse, it raced Reka's own scroll on the next frame, so the final scrollTop depended on which rAF resolved last. Dropping the manual math means the selected option lands wherever Reka puts it (align: 'start' by default), which is the standard dropdown behavior and works correctly across all sizes and slot content. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 9ccf738 commit da554f4

1 file changed

Lines changed: 2 additions & 17 deletions

File tree

resources/js/components/ui/Combobox/Combobox.vue

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -333,25 +333,10 @@ function pushTaggableOption(e) {
333333
updateModelValue([...props.modelValue ?? [], e.target.value]);
334334
}
335335
336-
async function scrollToSelectedOption() {
336+
function scrollToSelectedOption() {
337337
if (props.multiple || !props.modelValue) return;
338338
339-
await rootRef.value?.highlightSelected?.();
340-
341-
const index = filteredOptions.value.findIndex(
342-
(option) => getOptionValue(option) === props.modelValue
343-
);
344-
345-
if (index >= 0 && viewportRef.value) {
346-
const estimatedItemHeight = 40;
347-
const viewportHeight = viewportRef.value.clientHeight;
348-
const itemPosition = index * estimatedItemHeight;
349-
const centeredPosition = itemPosition - (viewportHeight / 2) + (estimatedItemHeight / 2);
350-
351-
requestAnimationFrame(() => {
352-
viewportRef.value.scrollTop = Math.max(0, centeredPosition);
353-
});
354-
}
339+
rootRef.value?.highlightSelected?.();
355340
}
356341
357342
function focus() {

0 commit comments

Comments
 (0)