question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Menu incorrectly triggers page scroll on hover

See original GitHub issue

Description

When I hover over a <Menu> which is partially off-screen, the page is scrolled. I don’t expect the page to ever scroll when hovering on a <MenuItem>.

Link to Reproduction

https://codesandbox.io/s/dawn-bash-516v70?file=/src/index.js

Steps to reproduce

  1. Click to open the menu

  2. Resize your browser so the menu goes off the bottom of the screen, but the top is visible:

    • Screenshot from 2022-02-21 13-19-10
  3. Hover over any menu item

  4. Notice the page scrolls (this is unexpected behaviour).

  5. Scroll the page so the menu goes off the top of the screen, but the bottom is visible:

    • Screenshot from 2022-02-21 13-22-31
  6. Hover over any menu item

  7. Notice the page scrolls (this is unexpected behaviour).

  8. Scroll the page so both the top and bottom go off the screen:

    • Screenshot from 2022-02-21 13-27-21
  9. Hover over any menu item

  10. Notice there is no scrolling (this is the correct behaviour).

  11. Resize your browser so the full menu fits on the screen (but so there’s still some vertical scroll):

    • Screenshot from 2022-02-21 13-29-23
  12. Hover over any menu item

  13. Notice there is no scrolling (this is the correct behaviour).

Chakra UI Version

1.8.5

Browser

Brave 1.35.101 (Chromium: 98.0.4758.87)

Operating System

  • Linux

Additional Information

I couldn’t reproduce the bug in Firefox v97.

Some debugging reveals the culprit as preventScroll: false here:

https://github.com/takethefake/chakra-ui/blob/main/packages/menu/src/use-menu.ts#L629-L631

Looks like this was introduced in https://github.com/chakra-ui/chakra-ui/pull/4514/files#diff-6c4aefbd3ea81ddacf70475aa13274ae14fbcc6609044c74a25c45f12bd9ff4eR616 to make the keyboard scrolling support better.

I wonder if there’s a better way to fix keyboard support? Or, perhaps alternatively; is there a way we can handle the hovering without having to re-focus every time?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:4
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
cwhenderson20commented, Jul 10, 2022

Still an issue. Pinging to keep the bot away.

3reactions
Alfxjxcommented, Feb 24, 2022
 <MenuList h={40} sx={{overflow:"scroll"}}>
  {Array.from(Array(20)).map((_, index) => (
    <MenuItem>Item {index + 1}</MenuItem>
  ))}
</MenuList>

this may help, using a scrollable menuList

Read more comments on GitHub >

github_iconTop Results From Across the Web

Menu hover effect causes unwanted movement - CSS-Tricks
But my problem is that when I hover over each item, the padding causes the other menu items to move over and also...
Read more >
Hover on scroll effect causes width of element to change
It happens because you are forcing it to show the scroll bar. It is the expected behavior, a scroll bar will always occupy...
Read more >
scroll-behavior - CSS: Cascading Style Sheets - MDN Web Docs
The scroll-behavior CSS property sets the behavior for a scrolling box when scrolling is triggered by the navigation or CSSOM scrolling APIs.
Read more >
Problem selecting SAP Web UI hover dropdown item - Activities
Hi, no it is not about scrolling down. The point is, that the click on a dropdown list item is not working. It...
Read more >
Reveal on hover | Webflow University
Use a hover interaction to reveal child elements when you hover over a parent ... sign next to Element Trigger and choose Mouse...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found