Skip to content

Commit 6665d5f

Browse files
committed
changed useEffect ons crollbar to also depend on zoom
1 parent a4aed0d commit 6665d5f

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

app/src/components/main/CanvasContainer.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,6 @@ function CanvasContainer(props: CanvasContainerProps): JSX.Element {
6969

7070
const container = document.getElementById('canvasContainer');
7171

72-
//useEffect dependency is the length of the parent components. No changes in children will scroll to the bottom. Once elements surpass the view of the canvas, scroll to bottom, else, keep scroll bar to the top.
73-
useEffect(() => {
74-
if (container && state.components[0].children.length > 0) {
75-
container.scrollTop = container.clientHeight;
76-
}
77-
}, [state.components[0].children.length]);
78-
7972
const [zoom, setZoom] = useState(1);
8073

8174
const zoomIn = () => {
@@ -86,6 +79,13 @@ function CanvasContainer(props: CanvasContainerProps): JSX.Element {
8679
setZoom(Math.max(zoom - 0.1, 0.1));
8780
};
8881

82+
//useEffect dependency is the length of the parent components. No changes in children will scroll to the bottom. Once elements surpass the view of the canvas, scroll to bottom, else, keep scroll bar to the top.
83+
useEffect(() => {
84+
if (container && state.components[0].children.length > 0) {
85+
container.scrollTop = container.scrollHeight;
86+
}
87+
}, [state.components[0].children.length, zoom]);
88+
8989
const buttonStyle: React.CSSProperties = {
9090
textAlign: 'center',
9191
color: '#ffffff',

0 commit comments

Comments
 (0)