Skip to content

Commit

Permalink
fix(/lib/components/modal): fix Modal expects document to exist
Browse files Browse the repository at this point in the history
So, I originally fixed this issue across every component in #124, but the bug was reintroduced by

resolve #609
  • Loading branch information
tulup-conner committed Feb 20, 2023
1 parent 35b0621 commit 7b093e5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/lib/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useEffect, useRef } from 'react';
import { createPortal } from 'react-dom';
import type { DeepPartial } from '..';
import { mergeDeep } from '../../helpers/mergeDeep';
import windowExists from '../../helpers/window-exists';
import { useKeyDown } from '../../hooks';
import type { FlowbiteBoolean, FlowbitePositions, FlowbiteSizes } from '../Flowbite/FlowbiteTheme';
import { useTheme } from '../Flowbite/ThemeContext';
Expand Down Expand Up @@ -57,7 +58,7 @@ export interface ModalProps extends PropsWithChildren<ComponentProps<'div'>> {
const ModalComponent: FC<ModalProps> = ({
children,
show,
root = document.body,
root,
popup,
size = '2xl',
position = 'center',
Expand All @@ -80,7 +81,8 @@ const ModalComponent: FC<ModalProps> = ({

// If the current value of the ref is not already a child of the root element,
// append it or replace its parent.
if (containerRef.current.parentNode !== root) {
if (containerRef.current.parentNode !== root && windowExists()) {
root = root || document.body;
root.appendChild(containerRef.current);
}

Expand Down

0 comments on commit 7b093e5

Please sign in to comment.