mui / mui/material-ui

[material-ui][Popover] The `disableScrollLock` prop is causing issues with CSS and additional scrolling functionality

Open
#42,320 7 comments 1 reaction 1 assignee View on GitHub

Nobody has claimed this yet.

component: Popover scope: popup support: docs-feedback
Dominant language
JavaScript
Stars
99.1k
Forks
32.5k
Avg merge
2d 17h
Merged PRs (30d)
106

Description

See Live example to reproduce

Link to live example: CodeSandBox Demo

https://github.com/mui/material-ui/assets/151521147/b46464bd-dc9b-474d-8f34-b66b162d911f

Current behavior

When the Popover is open without the disableScrollLock prop, is not allowing me to scroll through the page. In addition is adding padding-right and overflow:hidden to the body tag.

To prevent additional CSS from being apply to the body tag, I used disableScrollLock and also allows me to scroll on the page.
However this solution creates a second issue: **When the popover is active and the user still scrolls at a point where the button is not visible anymore, the popup remains open which i don't want **

I tried adding a useEffect hook to detect when the user scrolls more that 50 px and force the popover to close. Although it works it creates a 3rd issue where the popover is translated (moved) to the bottom left corner of the page for less than a second and then disappears.

Expected behavior

The required functionality is as follows:

  • The user clicks on the button to open the popover.
  • The user will be able to scroll while popover is open.
  • An open popover should not apply any css to the body tag.
  • When user scrolls more than 50px the popover should close (on spot, not at left bottom corner)
  • When user clicks somewhere else on the screen the popover should close
Context

I checked all ANCIENT previous questions but cannot find solution. Most questions below are more than 6-7 years old. There should be a solution by now. Don't say is duplicate if the duplicate question doesn't even have a reply with a valid structured answer.

Your environment

No response

Search keywords: popover, scroll, disableScrollLock

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.