Skip to content

Commit 8b1948a

Browse files
authored
fix: wrap scrollToIndex in requestAnimationFrame (#4132)
1 parent 7c25df1 commit 8b1948a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/select/parts/virtual-list.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,18 @@ const VirtualListOpen = forwardRef(
7373
menuEl: menuRefObject?.current,
7474
});
7575
} else {
76-
scrollToIndex(index);
76+
// Fix for AWSUI-61506. Defer scroll to next frame to ensure
77+
// virtual items are measured after re-render. When called from
78+
// parent's useEffect, measurements may not be ready yet.
79+
requestAnimationFrame(() => scrollToIndex(index));
7780
}
7881
}
7982
previousHighlightedIndex.current = index;
8083
},
8184
[firstOptionSticky, highlightType.moveFocus, scrollToIndex]
8285
);
8386

84-
const stickySize = firstOptionSticky ? virtualItems[0].size : 0;
87+
const stickySize = firstOptionSticky ? (virtualItems[0]?.size ?? 0) : 0;
8588
const withScrollbar = !!width && width.inner < width.outer;
8689

8790
const idPrefix = useUniqueId('select-list-');

0 commit comments

Comments
 (0)