Skip to content

Commit

Permalink
fix: modal-open class remains on body after modal closed
Browse files Browse the repository at this point in the history
The modal-open class remains on the body tag even after the modal is
closed. This is an issue of the reactstrap library
(reactstrap/reactstrap#1323) which is already
fixed buy not released yet.

Added a temporary work-around to remove the modal-open class when modal
is closed.

Closes #426
  • Loading branch information
Gido Manders committed Jun 22, 2020
1 parent ff41948 commit e6a7e2d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/core/OpenCloseModal/OpenCloseModal.tsx
Expand Up @@ -3,6 +3,7 @@ import { Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap';
import Button from '../Button/Button';
import { t } from '../../utilities/translation/translation';
import { BootstrapSize } from '../types';
import { useBodyFixOnModalClose } from '../useBodyFixOnModalClose/useBodyFixOnModalClose';

type Text = {
cancel?: string;
Expand Down Expand Up @@ -73,6 +74,8 @@ export function OpenCloseModal(props: Props) {
className
} = props;

useBodyFixOnModalClose(isOpen);

return (
<Modal
isOpen={isOpen}
Expand Down
10 changes: 10 additions & 0 deletions src/core/useBodyFixOnModalClose/useBodyFixOnModalClose.ts
@@ -0,0 +1,10 @@
/* istanbul ignore file */
import { useEffect } from 'react';

export function useBodyFixOnModalClose(isOpen: boolean) {
useEffect(() => {
if (!isOpen) {
document.querySelector('body')?.classList.remove('modal-open');
}
}, [isOpen]);
}
3 changes: 3 additions & 0 deletions src/form/ModalPicker/ModalPicker.tsx
Expand Up @@ -13,6 +13,7 @@ import {
import Pagination from '../../core/Pagination/Pagination';
import { t } from '../../utilities/translation/translation';
import SearchInput from '../../core/SearchInput/SearchInput';
import { useBodyFixOnModalClose } from '../../core/useBodyFixOnModalClose/useBodyFixOnModalClose';

interface Text {
placeholder?: string;
Expand Down Expand Up @@ -116,6 +117,8 @@ export default function ModalPicker(props: Props) {
text = {}
} = props;

useBodyFixOnModalClose(isOpen);

const shouldRenderPagination = !(page.first && page.last);

return (
Expand Down

0 comments on commit e6a7e2d

Please sign in to comment.