Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修正 popper.js 父元素 fixed 定位情况下错位的问题(#123) #214

Closed
wants to merge 3 commits into from

Conversation

squallliu
Copy link
Contributor

@squallliu squallliu commented Oct 12, 2022

fixed #123

@yiludege
Copy link
Collaborator

已经发布 appendOrInsertElementHook

直接采用这个 plugin 吧

  plugins: [
    {
      appendOrInsertElementHook: function (element, iframeWindow) {
        console.log(element, iframeWindow);
        if (element.offsetParent && element.offsetParent.tagName !== "BODY") {
          return;
        }
        const offsetParentDesc = Object.getOwnPropertyDescriptor(HTMLElement.prototype, "offsetParent");
        Object.defineProperties(element, {
          offsetParent: {
            configurable: true,
            get: function () {
              const offsetParent = offsetParentDesc.get.call(this);
              if ((offsetParent && offsetParent.tagName !== "BODY") || element.style.position !== "fixed") {
                return offsetParent;
              }
              return new Proxy(window.document.documentElement, {
                get: (target, propKey) => {
                  if (propKey === "parentNode") {
                    return iframeWindow.document.documentElement.parentNode;
                  }
                  const value = target[propKey];
                  const naughtySafari = typeof document.all === "function" && typeof document.all === "undefined";
                  // 只有这些场景下才需要 bind
                  if (
                    (naughtySafari
                      ? typeof value === "function" && typeof value !== "undefined"
                      : typeof value === "function") &&
                    !(value.name.indexOf("bound ") === 0 && !value.hasOwnProperty("prototype"))
                  ) {
                    const boundValue = Function.prototype.bind.call(value, target);
                    for (const key in value) {
                      boundValue[key] = value[key];
                    }
                    if (value.hasOwnProperty("prototype") && !boundValue.hasOwnProperty("prototype")) {
                      Object.defineProperty(boundValue, "prototype", {
                        value: value.prototype,
                        enumerable: false,
                        writable: true,
                      });
                    }
                    return boundValue;
                  }
                  return value;
                },
              });
            },
          },
        });
      },
    },
  ],

@wu529778790
Copy link

最新版本的"element-plus": "^2.3.7",已经是absolute了,但是依旧有问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

element-ui 弹框内使用select组件,弹出框位置异常
3 participants