diff --git a/packages/ffe-modals-react/package.json b/packages/ffe-modals-react/package.json index a8564aefef..3969dde375 100644 --- a/packages/ffe-modals-react/package.json +++ b/packages/ffe-modals-react/package.json @@ -26,7 +26,8 @@ }, "dependencies": { "@sb1/ffe-icons-react": "^11.0.2", - "@sb1/ffe-modals": "^0.2.10" + "@sb1/ffe-modals": "^0.2.10", + "dialog-polyfill": "^0.5.6" }, "devDependencies": { "@sb1/ffe-buildtool": "^0.7.1", diff --git a/packages/ffe-modals-react/src/Modal.tsx b/packages/ffe-modals-react/src/Modal.tsx index f47907a5f5..75c3cac6e6 100644 --- a/packages/ffe-modals-react/src/Modal.tsx +++ b/packages/ffe-modals-react/src/Modal.tsx @@ -62,6 +62,22 @@ export const Modal = React.forwardRef( } }, [isOpen]); + useEffect(() => { + if ( + typeof window !== 'undefined' && // to support Gatsby build(server side rendering) + dialogRef.current && + typeof dialogRef.current.showModal !== 'function' + ) { + import('dialog-polyfill').then( + ({ default: dialogPolyfill }) => { + if (dialogRef.current) { + dialogPolyfill.registerDialog(dialogRef.current); + } + }, + ); + } + }, []); + return createPortal( // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions null, +};