@@ -2,7 +2,7 @@ import Head from 'next/head';
2
2
import { AppProps } from 'next/app' ;
3
3
import Link from 'next/link' ;
4
4
import { useRouter } from 'next/router' ;
5
- import { useRef , useEffect } from 'react' ;
5
+ import { useRef , useEffect } from 'react' ;
6
6
7
7
import './styles.css' ;
8
8
import styles from './MainLayout.module.css' ;
@@ -27,11 +27,16 @@ const MainLayout: React.FunctionComponent<AppProps> = ({
27
27
28
28
useEffect ( ( ) => {
29
29
const resizeListener = ( ) => {
30
+ // Whenever the window expands to greater than 768 pixels,
31
+ // set the panelContents to their maximum height.
30
32
if ( window . innerWidth > 768 ) {
31
33
prevWindowWidth . current = window . innerWidth ;
32
34
panelContentsRef . current . style . maxHeight =
33
35
panelContentsRef . current . scrollHeight + 'px' ;
34
36
}
37
+ // Else when the window resizes to less than 768 pixels
38
+ // and we haven't already gone under 768 pixels on the previous resize,
39
+ // then set the height of panelContents to 0.
35
40
if ( window . innerWidth <= 768 && prevWindowWidth . current > 768 ) {
36
41
panelContentsRef . current . style . maxHeight = '0px' ;
37
42
}
@@ -43,6 +48,7 @@ const MainLayout: React.FunctionComponent<AppProps> = ({
43
48
} ;
44
49
} , [ ] ) ;
45
50
51
+ // Style .panelContents when clicking the expand icon.
46
52
const stylePanelOnExpand = ( ) => {
47
53
if ( panelContentsRef . current ) {
48
54
if ( panelContentsRef . current . style . maxHeight === '0px' ) {
@@ -58,7 +64,10 @@ const MainLayout: React.FunctionComponent<AppProps> = ({
58
64
}
59
65
} ;
60
66
67
+ //Style .panelContents when clicking on a link.
61
68
const stylePanelOnLink = ( ) => {
69
+ // Only hide the panelContents when our window size is less than 768 pixels.
70
+ // Otherwise maintain the current layout of panelContents.
62
71
if ( window . innerWidth <= 768 ) {
63
72
panelContentsRef . current . style . maxHeight = '0px' ;
64
73
panelContentsRef . current . style . overflow = 'hidden' ;
0 commit comments