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

Opening the drawer and then opening the modal from the drawer in combination with React Router sets the overflow: hidden on <body> element #21539

Closed
1 task done
bouchja1 opened this issue Feb 22, 2020 · 39 comments · Fixed by #25273
Labels

Comments

@bouchja1
Copy link

bouchja1 commented Feb 22, 2020

  • I have searched the issues of this repository and believe that this is not a duplicate.

Reproduction link

Edit on CodeSandbox

Steps to reproduce

  1. start react app
  2. localhost:3000 is loaded in the browser and there is element.style {} on html body element defined as expected
  3. click on "show drawer" button
  4. element.style {
    overflow: hidden;
    touch-action: none;
    } is set correctly on element because we have opened a Drawer component
  5. click on "ABC" or "DEF" buttons inside the Drawer
  6. close modal
  7. close drawer
  8. element.style {} is set correctly on elelemt
  9. click "Different" in list type item menu
  10. element.style { overflow: hidden; } is set on html body element of this page and I am not able to scroll until I refresh a browser

What is expected?

When both drawer and modal components are closed and I am linked to a different place in my single-page web app, I will be able to scroll a page.

What is actually happening?

When I open drawer component and then open modal component inside the drawer component, close both and am linked to a different place in my single-page web app, scrolling is not working because { overflow: hidden; } style is set to html body element

Environment Info
antd 3.26.11
React ^16.12.0
System macOS
Browser Chrome, Safari...

Please, is there any "hack" or something similar to make it work?

@bouchja1
Copy link
Author

bouchja1 commented Feb 22, 2020

I am not sure if this could be fully reproduced in CodeSandbox so you can clone and run my simple demo project here (https://github.com/bouchja1/ant-react-router-bug). Btw. if I set:

body { 
 ...
overflow: inherit|scroll|visible... (except hidden)
}

...I am temporarily ok with this hack... but should there occur any problem with this hack?

@bouchja1
Copy link
Author

Or probably better solution with

useEffect(() => { document.body.removeAttribute('style'); });

Placed before router switch. It wont make a background scroll while a modal is opened.

@AceNorth
Copy link

AceNorth commented Mar 4, 2020

Seeing the same issue, even without navigating to another page - if you dismiss a modal inside a drawer component, it will set { overflow: hidden; } on the html body.

You can also do document.body.style.removeProperty('overflow') as a hacky workaround a little less drastic than the above, until this issue is fixed.

@bouchja1
Copy link
Author

Seeing the same issue, even without navigating to another page - if you dismiss a modal inside a drawer component, it will set { overflow: hidden; } on the html body.

You can also do document.body.style.removeProperty('overflow') as a hacky workaround a little less drastic than the above, until this issue is fixed.

Hi @AceNorth, I have the same issue as you mentioned after I have upgraded to Ant v4.

overflow: hidden even without navigation to another page. So the temporary solution with document.body.style.removeProperty('overflow') does not work anymore.

I did not see any comments from Ant team. Don't know if this could be considered as a bug... or this is an intention.

@AceNorth
Copy link

AceNorth commented Mar 10, 2020

@bouchja1 It should still work, I think - you don't need to navigate to another page to call that function. I've added it as an afterClose method to the antd modal that was causing the problem.

@afc163
Copy link
Member

afc163 commented May 12, 2020

@jljsj33
Copy link
Member

jljsj33 commented Jun 8, 2020

这啥鬼问题啊,,为什么点 router 会加 overflow ?

@jljsj33
Copy link
Member

jljsj33 commented Jun 8, 2020

单个 overflow: hidden 应该是 modal 里加的。。。抽屉是加overflow: hidden; touch-action: none;

@jljsj33
Copy link
Member

jljsj33 commented Jun 8, 2020

https://github.com/react-component/dialog/blob/master/src/Dialog.tsx#L129, 这时的问题,,,那个谁还在给你们搞没,,@afc163

@jljsj33
Copy link
Member

jljsj33 commented Jun 8, 2020

this. inTransition 干吊用的??

@afc163
Copy link
Member

afc163 commented Jun 8, 2020

cc @shaodahong

@jljsj33
Copy link
Member

jljsj33 commented Jun 8, 2020

不对,,好像在 willunmount 之前刷了遍,,我晚上看下吧。。

@jljsj33
Copy link
Member

jljsj33 commented Jun 8, 2020

https://github.com/react-component/dialog/blob/master/src/Dialog.tsx#L150, 这里的问题,,这个加着干啥用的,是为了什么功能??@shaodahong

@jljsj33
Copy link
Member

jljsj33 commented Jun 8, 2020

如果是 1 的话不需要加 hidden 啊,前面的会处理的啊,leave 不是为了关闭吗??咋还放个开启的??

@shaodahong
Copy link
Member

https://github.com/react-component/dialog/blob/master/src/Dialog.tsx#L150, 这里的问题,,这个加着干啥用的,是为了什么功能??@shaodahong

switchScrollingEffect 里面会判断的

@shaodahong
Copy link
Member

这个 issue 的核心问题是用了 openCount 来判断是不是 effect,而 drawer 只有在某些情况下才会是 effect

@jljsj33
Copy link
Member

jljsj33 commented Jun 8, 2020

不对,,抽屉打开的时候,,openCount 就是 1 了,,,再开 modal 时, openCount 就是 2 了,,那关闭 modal 时就会触发 openCount =1 的问题了,,所以在关闭时要必须是 close 状态的,,现在关闭时会触发 open 的状态

@jljsj33
Copy link
Member

jljsj33 commented Jun 8, 2020

加了个判断。。

@shaodahong
Copy link
Member

不对,,抽屉打开的时候,,openCount 就是 1 了,,,再开 modal 时, openCount 就是 2 了,,那关闭 modal 时就会触发 openCount =1 的问题了,,所以在关闭时要必须是 close 状态的,,现在关闭时会触发 open 的状态

我会同时判断 openCount === 1和 isEffect

@jljsj33
Copy link
Member

jljsj33 commented Jun 8, 2020

leave 里只管理关闭状态,,关闭状态必须在 openCount 为 0 时才触发...

@jljsj33
Copy link
Member

jljsj33 commented Jun 8, 2020

@shaodahong
Copy link
Member

https://github.com/react-component/util/blob/master/src/PortalWrapper.js#L145-L156, 没有 isEffect 啊

Object.keys(cacheOverflow).length 这个就是

@jljsj33
Copy link
Member

jljsj33 commented Jun 8, 2020

这个不应该放在这里,,不是所有页面都会有 scroll 的

@shaodahong
Copy link
Member

这个不应该放在这里,,不是所有页面都会有 scroll 的

Modal 和 Drawer 都公用了这个,放在最底层没什么问题吧

@shaodahong
Copy link
Member

是 openCount 的问题,openCount 不能作为 effect 的判断,要单独拉出来一个 effectCount 这种

@jljsj33
Copy link
Member

jljsj33 commented Jun 8, 2020

我感觉是 overflow 和 scrollEffect 的方法你混在一起了的问题,,,应该分开,drawer 里的 overflow 时内部实现了的。。。

@shaodahong
Copy link
Member

Similar issue: #21894

@jljsj33
Copy link
Member

jljsj33 commented Jun 8, 2020

还有,,我上面的修复的逻辑也没错,,,animateLeave 时只管 openCount 为 0 时去切换 scrollEffect 的状态。。。

@jljsj33
Copy link
Member

jljsj33 commented Jun 8, 2020

想了一下,,放在一起好像也可以,,如果没有滚动条,,都不需要设 overflow: hidden,,先就放一起吧,我把 drawer 里的删了。。主要问题就是 animateLeave 时没做判断。。。

@shaodahong
Copy link
Member

想了一下,,放在一起好像也可以,,如果没有滚动条,,都不需要设 overflow: hidden,,先就放一起吧,我把 drawer 里的删了。。主要问题就是 animateLeave 时没做判断。。。

可以试试,后期还是要解决 openCount 的问题

@jljsj33
Copy link
Member

jljsj33 commented Jun 8, 2020

你看吧,,这个全权交给你了。。。

@jljsj33
Copy link
Member

jljsj33 commented Jun 8, 2020

reinstall antd

@KhoiNK
Copy link

KhoiNK commented Jun 22, 2020

I have the same problem. Have it get fixed yet?

Edit c3xwg

Reproduce steps:

  1. Click Open buton
  2. Click open modal button on the Drawer
  3. Close modal and drawer
  4. Click open modal button on the main page
    Now the page is not scrollable.
Environment Info
antd 3.25.1
React ^16.9.0
System macOS
Browser Chrome, Safari...

@RushilBasappa
Copy link

RushilBasappa commented Jun 26, 2020

Facing similar issue. Is there any alternative fix?

Using antd v3 which uses rc-dialog version of ~7.6 as its dependency

@jaysonberryhill
Copy link

Yea I am having the same issue. Do we know if/when a fix will be included in an upcoming release?

@vinaybagale
Copy link

It is still happening in version 4.8.4.

@JacopoLuri
Copy link

Still happened to me today.

solved with

afterClose={document.body.removeAttribute('style')}

@Alt-er
Copy link

Alt-er commented Jul 14, 2021

我也遇到了这个问题

afterClose={()=>{
setTimeout(()=>{ document.body.removeAttribute('style')} , 0)
}}

还必须使用setTimeout 才能重现滚动条

@disguised-uchiha
Copy link

afterClose={()=>document.body.style.removeProperty('overflow')}
this worked for me.
There is an afterClose property in Modal component.

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

Successfully merging a pull request may close this issue.