Skip to content

Commit

Permalink
Remove .bodyModalOpen class when Modal unmounts to allow body scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
julianguyen committed Jul 7, 2024
1 parent 6120eff commit 17e71f7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
11 changes: 10 additions & 1 deletion client/app/components/Modal/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// @flow
import React, {
useState, useRef, type Element, type Node,
useState,
useRef,
type Element,
type Node,
useEffect,
} from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faTimes } from '@fortawesome/free-solid-svg-icons';
Expand Down Expand Up @@ -64,6 +68,11 @@ export const Modal = (props: Props): Node => {

useFocusTrap(modalEl, open);

useEffect(() => () => {
const documentBody = ((document.body: any): HTMLBodyElement);
documentBody.classList.remove('bodyModalOpen');
}, []);

const handleKeyPress = (
event: SyntheticKeyboardEvent<HTMLDivElement>,
keyName: string,
Expand Down
16 changes: 12 additions & 4 deletions client/app/utils/__tests__/index.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ describe('Utils', () => {
metaElementTwo.setAttribute('name', 'pusher-cluster');
metaElementTwo.setAttribute('content', 'sample-cluster');

jest.spyOn(document, 'getElementsByTagName').mockImplementation(() => [metaElementOne, metaElementTwo]);
jest
.spyOn(document, 'getElementsByTagName')
.mockImplementation(() => [metaElementOne, metaElementTwo]);
});

it('should return null if window.Pusher is not defined', () => {
Expand All @@ -30,7 +32,9 @@ describe('Utils', () => {
window.Pusher = jest.fn();
const pusher = Utils.getPusher();
expect(pusher).toBeInstanceOf(window.Pusher);
expect(window.Pusher).toHaveBeenCalledWith('sample content', { cluster: 'sample-cluster' });
expect(window.Pusher).toHaveBeenCalledWith('sample content', {
cluster: 'sample-cluster',
});
});
});

Expand All @@ -45,10 +49,14 @@ describe('Utils', () => {
metaElementOne.setAttribute('name', 'csrf-token');
metaElementOne.setAttribute('content', 'TOKEN-TEST-VALUE');

jest.spyOn(document, 'getElementsByTagName').mockImplementation(() => [metaElementOne]);
jest
.spyOn(document, 'getElementsByTagName')
.mockImplementation(() => [metaElementOne]);

Utils.setCsrfToken();
expect(axios.defaults.headers.common['X-CSRF-Token']).toBe('TOKEN-TEST-VALUE');
expect(axios.defaults.headers.common['X-CSRF-Token']).toBe(
'TOKEN-TEST-VALUE',
);
});
});

Expand Down

0 comments on commit 17e71f7

Please sign in to comment.