Browse Source

fix: fix modal document in ssr (#2395)

* fix: fix modal document in ssr
代强 1 year ago
parent
commit
bf049be259
2 changed files with 4 additions and 4 deletions
  1. 3 3
      packages/semi-ui/modal/Modal.tsx
  2. 1 1
      packages/semi-ui/modal/ModalContent.tsx

+ 3 - 3
packages/semi-ui/modal/Modal.tsx

@@ -137,14 +137,14 @@ class Modal extends BaseComponent<ModalReactProps, ModalState> {
             disabledBodyScroll: () => {
                 const { getPopupContainer } = this.props;
                 this.bodyOverflow = document.body.style.overflow || '';
-                if ((!getPopupContainer || getPopupContainer() === document.body) && this.bodyOverflow !== 'hidden') {
+                if ((!getPopupContainer || getPopupContainer() === globalThis?.document?.body) && this.bodyOverflow !== 'hidden') {
                     document.body.style.overflow = 'hidden';
                     document.body.style.width = `calc(${this.originBodyWidth || '100%'} - ${this.scrollBarWidth}px)`;
                 }
             },
             enabledBodyScroll: () => {
                 const { getPopupContainer } = this.props;
-                if ((!getPopupContainer || getPopupContainer() === document.body) && this.bodyOverflow !== null && this.bodyOverflow !== 'hidden') {
+                if ((!getPopupContainer || getPopupContainer() === globalThis?.document?.body) && this.bodyOverflow !== null && this.bodyOverflow !== 'hidden') {
                     document.body.style.overflow = this.bodyOverflow;
                     document.body.style.width = this.originBodyWidth;
                 }
@@ -354,7 +354,7 @@ class Modal extends BaseComponent<ModalReactProps, ModalState> {
         } = {
             zIndex,
         };
-        if (getPopupContainer && getPopupContainer() !== document.body) {
+        if (getPopupContainer && getPopupContainer() !== globalThis?.document?.body) {
             wrapperStyle = {
                 zIndex,
                 position: 'static',

+ 1 - 1
packages/semi-ui/modal/ModalContent.tsx

@@ -308,7 +308,7 @@ export default class ModalContent extends BaseComponent<ModalContentReactProps,
         } = this.props;
         const { direction } = this.context;
         const classList = cls(className, {
-            [`${cssClasses.DIALOG}-popup`]: getPopupContainer && getPopupContainer() !== document.body && !maskFixed,
+            [`${cssClasses.DIALOG}-popup`]: getPopupContainer && getPopupContainer() !== globalThis?.document?.body && !maskFixed,
             [`${cssClasses.DIALOG}-fixed`]: maskFixed,
             [`${cssClasses.DIALOG}-rtl`]: direction === 'rtl',
         });