When I trigger a modal view in my page it triggers the scroll bar to disappear. It's an annoying effect because the background page starts moving when the modal moves in / disappears. Is there a cure for that effect?
Use the . modal-dialog-scrollable class to enable scrolling inside the modal.
Bootstrap 4.3 added new built-in scroll feature to modals. This makes only the modal-body content scroll if the size of the content would otherwise make the page scroll. To use it, just add the class modal-dialog-scrollable to the same div that has the modal-dialog class.
Approach: A simple solution to this problem is to set the value of the “overflow” property of the body element to “hidden” whenever the modal is opened, which disables the scroll on the selected element.
The issue was not because of "react-bootstrap" package. The issue is: you must have imported bootstrap css and bootstrap css in react-bootstrap package are clashing. Try importing css as follows: import "bootstrap/dist/css/bootstrap.
This is a feature, class modal-open
gets added to the HTML body
when you show the modal, and removed when you hide it.
This makes the scrollbar disappear since the bootstrap css says
.modal-open { overflow: hidden; }
You can override this by specifying
.modal-open { overflow: scroll; }
in your own css.
I think that inherit is better than scroll because when you open modal, it will always open with scroll, but when you don't have any scrolls you will get the same problem. So I just do this:
.modal-open { overflow: inherit; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With