Skip to content

Commit

Permalink
SICP-INTERACTIVE: Fix scrolling behaviour (#1811)
Browse files Browse the repository at this point in the history
* Fix scroll into view causing page to shift

* Fix prettier formatting
  • Loading branch information
samuelfangjw committed Jun 19, 2021
1 parent 35c076d commit 840cc11
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/pages/sicp/Sicp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,22 +109,22 @@ const Sicp: React.FC<SicpProps> = props => {
}, [section]);

// Scroll to correct position
React.useLayoutEffect(() => {
React.useEffect(() => {
const hash = props.location.hash;

if (!hash) {
if (topRef.current) {
topRef.current.scrollIntoView();
topRef.current.scrollIntoView({ block: 'nearest', behavior: 'smooth' });
}
return;
}

const ref = refs.current[hash];

if (ref) {
ref.scrollIntoView({ block: 'start' });
ref.scrollIntoView({ block: 'nearest', behavior: 'smooth' });
}
}, [props.location.hash, data]);
}, [props.location.hash]);

// Close all active code snippet when new page is loaded
React.useEffect(() => {
Expand Down
1 change: 0 additions & 1 deletion src/styles/_sicp.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ $sicp-background-color: #ffffff;
margin: 1em auto;
padding: 0 6em;
max-width: 1050px;

height: fit-content;
background-color: $sicp-background-color;

Expand Down

0 comments on commit 840cc11

Please sign in to comment.