This repository was archived by the owner on Dec 6, 2021. It is now read-only.
Commit e3082f8 1 parent c873efb commit e3082f8 Copy full SHA for e3082f8
File tree 1 file changed +14
-8
lines changed
src/components/virtual-scroll
1 file changed +14
-8
lines changed Original file line number Diff line number Diff line change @@ -106,20 +106,26 @@ const AtVirtualScroll = defineComponent({
106
106
107
107
watch ( ( ) => props . height , updateFirstAndLast )
108
108
watch ( ( ) => props . itemHeight , updateFirstAndLast )
109
- watch ( ( ) => props . scrollIntoItem , ( index , prevIndex ) => {
110
- const parsedIndex = parseInt ( `${ index } ` , 10 )
111
- if ( parsedIndex >= 0 && parsedIndex < props . items . length ) {
109
+ watch ( ( ) => props . scrollIntoItem , ( itemIndex , prevItemIndex ) => {
110
+ let parsedIndex = parseInt ( `${ itemIndex || 0 } ` , 10 )
111
+
112
+ // make sure index is within length of items
113
+ parsedIndex = Math . min ( props . items . length - 1 , Math . max ( 0 , parsedIndex ) )
114
+
115
+ scrollTop . value = parsedIndex * __itemHeight . value
116
+ updateFirstAndLast ( )
117
+ } )
118
+
119
+ onMounted ( ( ) => {
120
+ if ( Boolean ( props . scrollIntoItem ) ) {
121
+ let parsedIndex = parseInt ( `${ props . scrollIntoItem || 0 } ` , 10 )
112
122
scrollTop . value = parsedIndex * __itemHeight . value
113
123
updateFirstAndLast ( )
114
124
} else {
115
- warn ( `index should not exceed the length of items: ${ index } ` )
125
+ last . value = getLast ( 0 )
116
126
}
117
127
} )
118
128
119
- onMounted ( ( ) => {
120
- last . value = getLast ( 0 )
121
- } )
122
-
123
129
function getChildren ( ) {
124
130
return props . items . slice (
125
131
firstToRender . value ,
You can’t perform that action at this time.
0 commit comments