Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/components/AboutPageSideNavBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ const aboutPageSideNavBarItem: AboutPageSideNavBarItem[] = [
},
];

// eslint-disable-next-line no-shadow
export enum OverflowTypes {
unset = 'unset',
hidden = 'hidden',
}

export default function AboutPageSideNavBar({
pageKey,
}: {
Expand All @@ -66,6 +72,13 @@ export default function AboutPageSideNavBar({
const className = navOpen
? 'side-nav-about side-nav--open'
: 'side-nav-about';

if (typeof document !== 'undefined') {
document.body.style.overflow = navOpen
? OverflowTypes.hidden
: OverflowTypes.unset;
}

const navElement = useRef<HTMLElement | null>(null);
return (
<nav className={className} ref={navElement}>
Expand Down
12 changes: 12 additions & 0 deletions src/styles/about.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@

.side-nav-about {
@extend .side-nav;
top: 1.8rem;
overflow: hidden;
position: inherit;
width: auto;

&.side-nav--open {
@extend .side-nav--open;
width: 100%;
height: 100vh;
top: calc(var(--nav-height) * 2);
touch-action: none;
.side-nav__open {
top: 1.8rem;
}
}
}
5 changes: 3 additions & 2 deletions src/styles/learn.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* Needed since overflow: none will disable position: sticky on children */
clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
background-color: var(--color-fill-side-nav);
height: calc(100vh - var(--nav-height));
overflow: auto;
overflow-x: hidden;
padding: 0 var(--space-20);
Expand Down Expand Up @@ -153,7 +154,7 @@
}

.side-nav.side-nav--open .side-nav__open {
top: calc(var(--nav-height) + 2.4rem);
top: calc(var(--nav-height) + 1.6rem);
margin-bottom: -35px;
margin-top: 16px;
color: transparent;
Expand All @@ -180,7 +181,7 @@
overflow: visible;
overflow-y: scroll;
position: fixed;
top: calc(var(--nav-height) * 2);
top: var(--nav-height);
}

> :last-child {
Expand Down
24 changes: 23 additions & 1 deletion test/components/aboutPageSideNavBar.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import { render } from '@testing-library/react';
import { screen, render, fireEvent } from '@testing-library/react';
import AboutPageSideNavBar, {
AboutPageKeys,
OverflowTypes,
} from '../../src/components/AboutPageSideNavBar';

describe('AboutPageSideNavBar', () => {
Expand All @@ -28,4 +29,25 @@ describe('AboutPageSideNavBar', () => {
const activeLinks = innrerHtml.match('side-nav__item-community--active');
expect(activeLinks.length).toBe(1);
});
it('should set the body oveflow hidden on menu click', () => {
render(<AboutPageSideNavBar pageKey={AboutPageKeys.releases} />);
const downloadItem: Element = screen.getAllByRole('button')[0] as Element;
expect(document.body.style.overflow).toBe(OverflowTypes.unset);
fireEvent.click(downloadItem);
expect(document.body.style.overflow).toBe(OverflowTypes.hidden);
});

fit('should set the body overflow hidden/unset on toggling', () => {
render(<AboutPageSideNavBar pageKey={AboutPageKeys.releases} />);
const downloadItem: Element = screen.getAllByRole('button')[0] as Element;
expect(document.body.style.overflow).toBe(OverflowTypes.unset);
fireEvent.click(downloadItem);
expect(document.body.style.overflow).toBe(OverflowTypes.hidden);
fireEvent.click(downloadItem);
expect(document.body.style.overflow).toBe(OverflowTypes.unset);
fireEvent.click(downloadItem);
expect(document.body.style.overflow).toBe(OverflowTypes.hidden);
fireEvent.click(downloadItem);
expect(document.body.style.overflow).toBe(OverflowTypes.unset);
});
});