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

how to remove the right padding of body when show a modal #1422

Closed
yzy1197988245 opened this issue May 10, 2018 · 9 comments · Fixed by #1877
Closed

how to remove the right padding of body when show a modal #1422

yzy1197988245 opened this issue May 10, 2018 · 9 comments · Fixed by #1877
Assignees

Comments

@yzy1197988245
Copy link

What problem does this feature solve?

每次show modal 的时候右边多一个空白,body不会出现滚动条

What does the proposed API look like?

加一个配置项

@hemiaoio
Copy link

同样关注ing...

@wzhudev
Copy link
Member

wzhudev commented May 12, 2018

It seems that it was fixed in recent commits. See https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/components/modal/nz-modal.component.ts.

private changeBodyOverflow(): void {
    const openModals = this.modalControl.openModals;

    if (openModals.length) {
      this.renderer.setStyle(this.document.body, 'padding-right', `${this.nzMeasureScrollbarService.scrollBarWidth}px`);
      this.renderer.setStyle(this.document.body, 'overflow', 'hidden');
    } else {
      this.renderer.removeStyle(this.document.body, 'padding-right');
      this.renderer.removeStyle(this.document.body, 'overflow');
    }
  }

But I think the padding should be added before the modal shows up, just like antd.

@wilsoncook
Copy link
Member

@yzy1197988245 @hemiaoio
Now the modal shown strategy is the same with antd, let's make it more clear, do you want a option to avoid adding the padding-right:Npx to body?

@hemiaoio
Copy link

@wilsoncook YES. Now open the modal window, the back window will shake, visually feel uncomfortable

@yzy1197988245
Copy link
Author

@wilsoncook YES

@lopn
Copy link

lopn commented Jun 25, 2018

this.renderer.setStyle(this.document.body, 'padding-right', `${this.nzMeasureScrollbarService.scrollBarWidth}px`);

@lopn
Copy link

lopn commented Jun 25, 2018

padding-right 不能每次都加, 我觉得最合理的是应该先判断页面是否有滚动条,如果有获取bar宽度,加padding-right, 否则不加

@lopn
Copy link

lopn commented Jun 25, 2018

修改成

  get scrollBarWidth(): number {
    if(document.body.scrollHeight <= (window.innerHeight || document.documentElement.clientHeight)){
         return 0;
      }

    if (isNotNil(this._scrollbarWidth)) {
      return this._scrollbarWidth;
    }
    this.initScrollBarWidth();
    return this._scrollbarWidth;
  }

@lock
Copy link

lock bot commented Aug 19, 2019

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants