Skip to content

Commit c319d22

Browse files
committed
Fix scrolling
1 parent 434ecbb commit c319d22

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

src/pages/quick-start/index.tsx

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,38 @@ export default function IntegrationBuilderPage(props: any) {
101101

102102
const el = e.target as HTMLDivElement;
103103
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;
104108

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;
112128
}
113129
}
114130
}
131+
132+
// Only update if the closest step is different from current
133+
if (closestIndex !== stepIndex) {
134+
onChangeStep(closestIndex);
135+
}
115136
};
116137

117138
// const onChangeOptionValue = (optionKey: string, event: ChangeEvent<HTMLInputElement>) => {

0 commit comments

Comments
 (0)