Skip to content

Commit 6755973

Browse files
committed
edited scroll functionality when elements fit in page vs not
1 parent 6665d5f commit 6755973

File tree

2 files changed

+69
-55
lines changed

2 files changed

+69
-55
lines changed

app/src/components/main/Canvas.tsx

Lines changed: 52 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -335,63 +335,61 @@ const Canvas = forwardRef<HTMLDivElement, CanvasProps>(({ zoom }, ref) => {
335335
};
336336

337337
return (
338-
<div>
339-
<div
340-
className={'componentContainer'}
341-
ref={drop}
342-
data-testid="drop"
343-
style={canvasStyle}
344-
onClick={onClickHandler}
345-
onMouseMove={handleMouseMove}
346-
>
347-
{renderChildren(currentComponent.children)}
348-
{remoteCursors.map(
349-
(cursor, idx) =>
350-
cursor.isVisible && (
351-
<div
352-
key={idx}
353-
className="remote-cursor"
354-
style={{
355-
position: 'absolute',
356-
left: cursor.x + 'px',
357-
top: cursor.y - 68 + 'px',
358-
//cursor style
359-
fontSize: '1em',
360-
color: userColors[userList.indexOf(cursor.remoteUserName)]
361-
}}
362-
>
363-
{<FaMousePointer />}
364-
{cursor.remoteUserName}
365-
</div>
366-
)
367-
)}
368-
<label className="switch">
369-
{userList.length > 1 && (
370-
<Button
371-
className="btn-toggle"
372-
onClick={multipleClicks}
338+
<div
339+
className={'componentContainer'}
340+
ref={drop}
341+
data-testid="drop"
342+
style={canvasStyle}
343+
onClick={onClickHandler}
344+
onMouseMove={handleMouseMove}
345+
>
346+
{renderChildren(currentComponent.children)}
347+
{remoteCursors.map(
348+
(cursor, idx) =>
349+
cursor.isVisible && (
350+
<div
351+
key={idx}
352+
className="remote-cursor"
373353
style={{
374-
position: 'fixed',
375-
width: '100px',
376-
height: '35px',
377-
bottom: '200px',
378-
right: '45vw',
379-
padding: '5px',
380-
textAlign: 'center',
381-
color: '#ffffff',
382-
backgroundColor: '#151515',
383-
zIndex: 0,
384-
border: '2px solid #354e9c',
385-
whiteSpace: 'nowrap',
386-
cursor: 'pointer',
387-
textTransform: 'none'
354+
position: 'absolute',
355+
left: cursor.x + 'px',
356+
top: cursor.y - 68 + 'px',
357+
//cursor style
358+
fontSize: '1em',
359+
color: userColors[userList.indexOf(cursor.remoteUserName)]
388360
}}
389361
>
390-
{toggleText === 'on' ? 'View Cursors' : 'Hide Cursors'}
391-
</Button>
392-
)}
393-
</label>
394-
</div>
362+
{<FaMousePointer />}
363+
{cursor.remoteUserName}
364+
</div>
365+
)
366+
)}
367+
<label className="switch">
368+
{userList.length > 1 && (
369+
<Button
370+
className="btn-toggle"
371+
onClick={multipleClicks}
372+
style={{
373+
position: 'fixed',
374+
width: '100px',
375+
height: '35px',
376+
bottom: '200px',
377+
right: '45vw',
378+
padding: '5px',
379+
textAlign: 'center',
380+
color: '#ffffff',
381+
backgroundColor: '#151515',
382+
zIndex: 0,
383+
border: '2px solid #354e9c',
384+
whiteSpace: 'nowrap',
385+
cursor: 'pointer',
386+
textTransform: 'none'
387+
}}
388+
>
389+
{toggleText === 'on' ? 'View Cursors' : 'Hide Cursors'}
390+
</Button>
391+
)}
392+
</label>
395393
</div>
396394
);
397395
});

app/src/components/main/CanvasContainer.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ function CanvasContainer(props: CanvasContainerProps): JSX.Element {
6868
const containerRef = useRef<HTMLDivElement>(null);
6969

7070
const container = document.getElementById('canvasContainer');
71+
const components = document.querySelector('.componentContainer');
7172

7273
const [zoom, setZoom] = useState(1);
7374

@@ -81,7 +82,22 @@ function CanvasContainer(props: CanvasContainerProps): JSX.Element {
8182

8283
//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.
8384
useEffect(() => {
84-
if (container && state.components[0].children.length > 0) {
85+
if (
86+
container &&
87+
components &&
88+
state.components[0].children.length > 0 &&
89+
components.scrollHeight == components.clientHeight
90+
) {
91+
console.log('if components scroll height', components.scrollHeight);
92+
console.log('if components client height', components.clientHeight);
93+
console.log('if container scroll height', container.scrollHeight);
94+
console.log('if container client height', container.clientHeight);
95+
container.scrollTop = 0;
96+
} else if (container && components) {
97+
console.log('else components scroll height', components.scrollHeight);
98+
console.log('else components client height', components.clientHeight);
99+
console.log('else container scroll height', container.scrollHeight);
100+
console.log('else container client height', container.clientHeight);
85101
container.scrollTop = container.scrollHeight;
86102
}
87103
}, [state.components[0].children.length, zoom]);

0 commit comments

Comments
 (0)