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

Message: Fix removed element offsetHeight calculation bug #17696

Closed
wants to merge 1 commit into from

Conversation

Aras-ax
Copy link

@Aras-ax Aras-ax commented Oct 12, 2019

message组件,同时弹出多个消息的情况下,前一个消息框消失,计算offsetHeight的元素选择错误,会出现后面的消息框没置顶,或者覆盖的情况,在线演示见message bug
message bug

错误见代码中的注释

Message.close = function(id, userOnClose) {
  let len = instances.length;
  let index = -1;
  for (let i = 0; i < len; i++) {
    if (id === instances[i].id) {
      index = i;
      if (typeof userOnClose === 'function') {
        userOnClose(instances[i]);
      }
      instances.splice(i, 1);
      break;
    }
  }
  if (len <= 1 || index === -1 || index > instances.length - 1) return;
 // 这个地方计算的是 instances.splice(i, 1);移除后数组中的实例,index对应的instance不是被移除的那个元素,计算的offsetHeight 不正确
  const removedHeight = instances[index].$el.offsetHeight;
  for (let i = index; i < len - 1 ; i++) {
    let dom = instances[i].$el;
    dom.style['top'] =
      parseInt(dom.style['top'], 10) - removedHeight - 16 + 'px';
  }
};

@element-bot
Copy link
Member

Deploy preview for element ready!

Built with commit 529c509

https://deploy-preview-17696--element.netlify.com

@island205
Copy link
Contributor

Thanks
Duplicate of #17852

@island205 island205 closed this Oct 30, 2019
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.

None yet

3 participants