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

Background scrolls when modal is open #3

Closed
shafi- opened this issue Apr 27, 2021 · 2 comments
Closed

Background scrolls when modal is open #3

shafi- opened this issue Apr 27, 2021 · 2 comments

Comments

@shafi-
Copy link

shafi- commented Apr 27, 2021

Describe the bug
When any modal is open and user tries to scroll, the page in the background scrolls.

To Reproduce
Steps to reproduce the behavior:

  1. Go to 'https://kimia-ui.vercel.app/components/modal'
  2. Open any modal
  3. Scroll up or down'
  4. See the background page is scrolling

Expected behavior
When modal is open, user should be able to scroll only the modal contents if it has scrollable contents.

Screenshots
https://gyazo.com/d5a9336fd65f175f7b9ae8fee9c94f14

Desktop (please complete the following information):

  • OS: [Windows]
  • Browser [Chrome]
  • Version 90.0.4430.85

Smartphone (please complete the following information):

  • Not tested
@enochndika
Copy link
Owner

This is an intended behavior.

If you want to prevent body from scrolling when a modal is opened , in the logical part of the component add another useEffect

  useEffect(() => {
    if (isOpen) {
      document.body.style.position = "fixed";
      document.body.style.width = "100%";
    }
  }, [isOpen]);

@enochndika enochndika pinned this issue Apr 28, 2021
@shafi-
Copy link
Author

shafi- commented Apr 28, 2021

Thank you for the nice work and the reply.
I am not sure - in which case, someone would like to scroll the body while the modal is open. My suggestion would be, to make "prevent body from scrolling when modal open" intended behavior because most of the component providers like Bootstrap/ ant.design etc are doing in that way and that is realistic.

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

No branches or pull requests

2 participants