Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material UI - Unblock scrolling when popover is opened

The scroll is blocked with Popover according to the new material-ui version doc.

When i open the popover, the scroll-bar of the web page suddenly disappeared and it's not the part of user experience in my opinion.

I wanna keep the scroll bar visible while popover is open.

I'm using Material-UI V3.8.1.

like image 809
Tommy Avatar asked Dec 31 '18 08:12

Tommy


2 Answers

The property you are looking for is called disableScrollLock. But using this, does not recalculate the modals positioning and you will have a floating modal in your application. Instead, as described by a few others here, the Popper should be used.

like image 192
Viktor Leandersson Avatar answered Nov 12 '22 12:11

Viktor Leandersson


it can be fixed by using container props of Popover. container props is a node, component instance or function that returns either. The container will passed to the Modal component. By default, it uses the body of the anchorEl's top-level document object, so it's simply document.body most of the time. This default setting is making document removing scroll bar. So i just used its direct parent for container instead of default setting and it solved the problem. :)

<Popover
  open={...}
  anchorEl={...}
  anchorOrigin={...}
  container={this.AnchorEl.parentNode}
>

Thanks

like image 10
Tommy Avatar answered Nov 12 '22 11:11

Tommy