浏览代码

Merge pull request #1744 from nekocode/fix-document-not-defined

fix: fix document is not defined
代强 2 年之前
父节点
当前提交
bbaaabe2f2
共有 1 个文件被更改,包括 12 次插入12 次删除
  1. 12 12
      packages/semi-ui/_portal/index.tsx

+ 12 - 12
packages/semi-ui/_portal/index.tsx

@@ -52,25 +52,25 @@ class Portal extends PureComponent<PortalProps, PortalState> {
         }
     }
 
-    initContainer = (context: ContextValue, catchError = false)=>{
-        let container: HTMLElement|undefined = undefined;
-        if (!this.el) {
-            this.el = document.createElement('div');
-        }
-        if (!this.state?.container) {
-            try {
+    initContainer = (context: ContextValue, catchError = false) => {
+        try {
+            let container: HTMLElement | undefined = undefined;
+            if (!this.el) {
+                this.el = document.createElement('div');
+            }
+            if (!this.state?.container) {
                 this.el = document.createElement('div');
                 const getContainer = this.props.getPopupContainer || context.getPopupContainer || defaultGetContainer;
                 const portalContainer = getContainer();
                 portalContainer.appendChild(this.el);
                 this.addStyle(this.props.style);
                 this.addClass(this.props.prefixCls, context, this.props.className);
-                container = portalContainer; 
+                container = portalContainer;
                 return container;
-            } catch (e) {
-                if (!catchError) {
-                    throw e;
-                }
+            }
+        } catch (e) {
+            if (!catchError) {
+                throw e;
             }
         }
         return this.state?.container;