@@ -101,17 +101,38 @@ export default function IntegrationBuilderPage(props: any) {
101
101
102
102
const el = e . target as HTMLDivElement ;
103
103
const stepEls = el . getElementsByClassName ( styles . stepContainer ) ;
104
+ const containerHeight = el . clientHeight ;
105
+ const scrollTop = el . scrollTop ;
106
+ const scrollHeight = el . scrollHeight ;
107
+ const viewportCenter = scrollTop + containerHeight / 2 ;
104
108
105
- for ( let i = 0 ; i < stepEls . length ; i += 1 ) {
106
- const stepEl = stepEls . item ( i ) as HTMLDivElement ;
107
- if ( el . scrollTop <= stepEl . offsetTop ) {
108
- const dis = stepEl . offsetTop - el . scrollTop ;
109
- if ( dis >= 700 && dis <= 800 ) {
110
- onChangeStep ( i ) ;
111
- break ;
109
+ // Check if we're at the bottom of the scroll container
110
+ const isAtBottom = scrollTop + containerHeight >= scrollHeight - 5 ; // 5px tolerance
111
+
112
+ let closestIndex = 0 ;
113
+ let closestDistance = Infinity ;
114
+
115
+ // If we're at the bottom, automatically select the last element
116
+ if ( isAtBottom && stepEls . length > 0 ) {
117
+ closestIndex = stepEls . length - 1 ;
118
+ } else {
119
+ // Otherwise, find the element closest to center
120
+ for ( let i = 0 ; i < stepEls . length ; i += 1 ) {
121
+ const stepEl = stepEls . item ( i ) as HTMLDivElement ;
122
+ const elementCenter = stepEl . offsetTop + stepEl . offsetHeight / 2 ;
123
+ const distance = Math . abs ( viewportCenter - elementCenter ) ;
124
+
125
+ if ( distance < closestDistance ) {
126
+ closestDistance = distance ;
127
+ closestIndex = i ;
112
128
}
113
129
}
114
130
}
131
+
132
+ // Only update if the closest step is different from current
133
+ if ( closestIndex !== stepIndex ) {
134
+ onChangeStep ( closestIndex ) ;
135
+ }
115
136
} ;
116
137
117
138
// const onChangeOptionValue = (optionKey: string, event: ChangeEvent<HTMLInputElement>) => {
0 commit comments