File tree Expand file tree Collapse file tree
Website/components/datamodelview Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -159,9 +159,7 @@ export const List = ({ setCurrentIndex }: IListProps) => {
159159 return ;
160160 }
161161
162- rowVirtualizer . scrollToIndex ( sectionIndex , {
163- align : 'start'
164- } ) ;
162+ smartScrollToIndex ( sectionIndex ) ;
165163
166164 } , [ flatItems ] ) ;
167165
@@ -175,9 +173,7 @@ export const List = ({ setCurrentIndex }: IListProps) => {
175173 return ;
176174 }
177175
178- rowVirtualizer . scrollToIndex ( groupIndex , {
179- align : 'start'
180- } ) ;
176+ smartScrollToIndex ( groupIndex ) ;
181177 } , [ flatItems ] ) ;
182178
183179 const restoreSection = useCallback ( ( ) => {
@@ -202,6 +198,23 @@ export const List = ({ setCurrentIndex }: IListProps) => {
202198 }
203199 } , [ rowVirtualizer ] ) ;
204200
201+ const smartScrollToIndex = useCallback ( ( index : number ) => {
202+ rowVirtualizer . scrollToIndex ( index , { align : 'start' } ) ;
203+
204+ const tryFix = ( ) => {
205+ const mounted = rowVirtualizer . getVirtualItems ( ) . some ( v => v . index === index ) ;
206+ if ( ! mounted ) {
207+ requestAnimationFrame ( tryFix ) ;
208+ return ;
209+ }
210+
211+ requestAnimationFrame ( ( ) => {
212+ rowVirtualizer . scrollToIndex ( index , { align : 'start' } ) ;
213+ } ) ;
214+ } ;
215+ requestAnimationFrame ( tryFix ) ;
216+ } , [ rowVirtualizer ] ) ;
217+
205218 return (
206219 < >
207220 < Box className = { `absolute w-full h-full flex items-center justify-center z-[100] transition-opacity duration-300 ${ loadingSection ? 'opacity-100' : 'opacity-0 pointer-events-none' } ` } >
You can’t perform that action at this time.
0 commit comments