Skip to content

Commit

Permalink
fix document is undefined when EuiOverlayMask is visible at start
Browse files Browse the repository at this point in the history
  • Loading branch information
jeepers3327 committed Dec 1, 2021
1 parent 5e322a8 commit 985633b
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/components/overlay_mask/overlay_mask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const EuiOverlayMask: FunctionComponent<EuiOverlayMaskProps> = ({
headerZindexLocation = 'above',
...rest
}) => {
const overlayMaskNode = useRef<HTMLDivElement>(document.createElement('div'));
const overlayMaskNode = useRef<HTMLDivElement>();
const [isPortalTargetReady, setIsPortalTargetReady] = useState(false);

useEffect(() => {
Expand All @@ -63,10 +63,16 @@ export const EuiOverlayMask: FunctionComponent<EuiOverlayMaskProps> = ({
};
}, []);

useEffect(() => {
if (typeof document !== undefined) {
overlayMaskNode.current = document.createElement('div');
}
}, []);

useEffect(() => {
const portalTarget = overlayMaskNode.current;

if (document !== undefined) {
if (typeof document !== undefined && overlayMaskNode.current) {
document.body.appendChild(overlayMaskNode.current);
}

Expand All @@ -87,7 +93,9 @@ export const EuiOverlayMask: FunctionComponent<EuiOverlayMaskProps> = ({
`Unhandled property type. EuiOverlayMask property ${key} is not a string.`
);
}
overlayMaskNode.current.setAttribute(key, rest[key]!);
if (overlayMaskNode.current) {
overlayMaskNode.current.setAttribute(key, rest[key]!);
}
});
}, []); // eslint-disable-line react-hooks/exhaustive-deps

Expand Down

0 comments on commit 985633b

Please sign in to comment.