Popover having anchor issues with disableScrollLock prop

React v.18.3.1

react-native v.0.74.1

@mui v.5.15.3


I have a popover which is triggered by an icon button. and closes in the following two scenarios:

  • When the user clicks somewhere in the screen
  • When the user scroll more than 50 px in any y-direction (up or down)
const [popoverAnchor, setPopoverAnchor] = useState(null);
const [popoverInfo, setPopoverInfo] = useState(null); 
const [initialScrollPosition, setInitialScrollPosition] = useState(null);

//On Questionmark Button Click
const openPopover = (event, infoText) => {
    setInitialScrollPosition(window.scrollY); 
    setPopoverAnchor(event.currentTarget);
    setPopoverInfo(popoverInfo => popoverInfo && popoverInfo.text === infoText ? null : { anchor: popoverAnchor, text: infoText });
};

//Popover OnClose Event Listener Triggers this function
const closePopover = () => {
    setPopoverInfo(null);
    setPopoverAnchor(null);
};

useEffect(() => {
    const handleScroll = () => {
        if (initialScrollPosition !== null && Math.abs(window.scrollY - initialScrollPosition) > 50) {
            closePopover();
            setInitialScrollPosition(null);
        }
    };

    window.addEventListener('scroll', handleScroll);
    return () => {
        window.removeEventListener('scroll', handleScroll);
    };
}, [initialScrollPosition]);

<IconButton onClick={(e) => openPopover(e, item.infoText)} size="small">
      <HelpOutlineIcon />
</IconButton>

<Popover
      open={Boolean(popoverAnchor)}
      anchorEl={popoverAnchor}
      onClose={closePopover}
      anchorOrigin={{
            vertical: 'bottom',
            horizontal: 'left',
      }}
      transformOrigin={{
            vertical: 'top',
            horizontal: 'left'
      }}
      >
      text
</Popover>

The above code is working great however when the popover is triggered is adding padding-right:17px and overflow:hidden on the <body> tag for some reason. To address this issue i have added disableScrollLock on the popover which solves the issue (Related GitHub Issue: 19961)

<Popover disableScrollLock ...></Popover>

With the above solution the scenario “When the user clicks somewhere in the screen” is still working but the disableScrollLock is causing issues on “When the user scroll more than 50 px in any y-direction (up or down)”


THE ISSUE:
When the popover is open and the user is scrolling the popover is moving to the bottom-left corner of the screen and then disappears instead of disappearing on current anchor location.(similar github issue 8567) and youtube video demo

I’m not exactly sure why this is happening and I’m fairly new to React, but the require solution i want should have the following:

  • Popover should close on spot, when the user clicks somewhere in the screen
  • Popover should close on spot, when the user scroll more than 50 px in any y-direction
  • Popover should open without adding additional CSS to the tag

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật