You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Menu automatically dismisses on web when outside the bounds of the window #3854
On web on desktop browsers (at least on macOS), when a Menu attempts to display and it partially falls outside the bounds of the browser window, it auto-dismisses.
Expected behaviour
Ideally, the Menu would position itself so that it would not attempt to display outside the bounds of the browser window, so that no scrolling is needed. But if it does attempt to display outside the bounds of the browser window, it would not auto-dismiss, so that at least the user can access it by scrolling.
Open the app in any desktop web browser (tested in Chrome, Safari, and Firefox for Mac)
Click each menu button
Expected: the menu displays for all buttons
Actual: on any web browser for Mac, the left and right menus display, but the right button flashes and is automatically dismissed
Note: the bug does not occur on iOS or Android native, on iOS Safari, or on Android Chrome.
Preview
menu-web-auto-dismiss.mov
What have you tried so far?
Tried adjusting anchorPosition so the Menu displays within the window. But since it is displaying off to the right, anchorPosition's top and bottom don't help. It might be a workaround if we could anchor to left and right, similar to MUI: https://mui.com/material-ui/react-popover/#anchor-playground
Tried adding margin to the right of the button so that the menu fully fits within the browser window. This prevents triggering the issue, but will be challenging for my use case on small screens.
Your Environment
software
version
ios
16.2
android
n/a
react-native
0.71.7
react-native-paper
5.7.0
node
18.15.0
npm or yarn
yarn 1.22.19
expo sdk
48.0.15
Reacted by Kevin Lin, Emir Bachter and Siddharth Panjwani
I have the same problem. Any solusions? If the menu over the right or bottom edges of the screen, a screen redraw will occur and the menu will be automatically dismissed.
In this sample, the menu is not automatically dismissed, But when the menu is displayed by clicking on the right or bottom edge of the screen, a scrollbar appears for a moment, and the scrollbar also appears to change with the easing of the menu.
Another problem is when I have a list of let's say for example 100 items inside the menu. In this case, the menu won't open. Cause the height of the list becomes bigger than the screen. I tried to put a flatlist inside and everything works ok, but I don't think it is the best solution. Any solutions, please?
I think this is not a solution but more like a workaround that wrapping the menu inside PaperProvider seems to avoid the menu from automatically dismissing.
We're really open to getting help and contributions for the library! If you'd like to explore the issue and share your solution, we'd truly appreciate it.
Same here. The menu takes a sec to show and then dismisses within a sec of showing. It actually shows up properly when I wrap the component with BUT it messes up the rest of the layout.
Using the latest React Native Paper and Expo SDK 50.
In my experimentation, the workaround appears to be inserting the "overflow: 'hidden'" style into your view hierarchy at an appropriate location. How do you find the appropriate location?
Open the dev tools and go to the "elements" (DOM) view
Open the menu
As the menu appears briefly (and then immediately disappears), you'll see a new div element appear in the DOM. You'll then need to apply the "overflow: 'hidden'" style ABOVE that level. In my case, the root of my app was a PaperProvider. I added a view above this level with the overflow style set to hidden, and now the menu sticks around correctly. YMMV, but I hope this helps!
I have done some investigation into what is causing the the menu to disappear after opening. It seems like sometimes on windows the menu opening will cause scroll bars to appear for a split second. The scroll bars appearing will cause the dimensions of the window to change triggering the dimensions listener inside the Menu component which triggers the onDismiss prop. As @lukewis mentioned adding overflow: "hidden" as a wrapper around the PaperProvider will work, but in my case it was breaking ScrollViews on some screens because the PaperProvider was wrapping my App Component.
What I have done is add a view that wraps all content under the Portal inside the Menu component. This view contains the overflow: "hidden" style. This is working nicely.
Activity
jboyan commentedon Apr 30, 2023
see also #3716
CodingItWrong commentedon May 1, 2023
Thanks @jboyan, #3678 (linked from #3716) seems relates too
nappa0326 commentedon May 19, 2023
I have the same problem. Any solusions? If the menu over the right or bottom edges of the screen, a screen redraw will occur and the menu will be automatically dismissed.
https://snack.expo.dev/@nappa0326/popupmenusample?platform=web
In this sample, the menu is not automatically dismissed, But when the menu is displayed by clicking on the right or bottom edge of the screen, a scrollbar appears for a moment, and the scrollbar also appears to change with the easing of the menu.
ErionTp commentedon May 27, 2023
Another problem is when I have a list of let's say for example 100 items inside the menu. In this case, the menu won't open. Cause the height of the list becomes bigger than the screen. I tried to put a flatlist inside and everything works ok, but I don't think it is the best solution. Any solutions, please?
nappa0326 commentedon Jun 20, 2023
anybody there? I tried with 5.8.0 and it was not fixed..
dheeraj539 commentedon Jul 25, 2023
Facing the same issue after upgrading my expo SDK version from 45 to 46 (Working without any issues in expo SDK 45)
yang-sprinter commentedon Aug 14, 2023
I am also running into this issue.
augini commentedon Sep 12, 2023
I think this is not a solution but more like a workaround that wrapping the menu inside PaperProvider seems to avoid the menu from automatically dismissing.
jarredkenny commentedon Sep 14, 2023
Having the same problem. The wrapping in PaperProvider just pushes things around in my layout.
yang-sprinter commentedon Sep 14, 2023
@lukewalczak would you be able to look into or suggest a solution for this? Seems like a number of folks are still running into this issue.
VladTabacariu commentedon Oct 12, 2023
can confirm. same here. the menu autodismises if its left most positioned.
lukewalczak commentedon Oct 12, 2023
We're really open to getting help and contributions for the library! If you'd like to explore the issue and share your solution, we'd truly appreciate it.
dzinreach commentedon Dec 17, 2023
Same here. The menu takes a sec to show and then dismisses within a sec of showing. It actually shows up properly when I wrap the component with BUT it messes up the rest of the layout.
Using the latest React Native Paper and Expo SDK 50.
If anyone finds a workaround please share.
lukewis commentedon Jan 12, 2024
In my experimentation, the workaround appears to be inserting the "overflow: 'hidden'" style into your view hierarchy at an appropriate location. How do you find the appropriate location?
As the menu appears briefly (and then immediately disappears), you'll see a new div element appear in the DOM. You'll then need to apply the "overflow: 'hidden'" style ABOVE that level. In my case, the root of my app was a PaperProvider. I added a view above this level with the overflow style set to hidden, and now the menu sticks around correctly. YMMV, but I hope this helps!
MorganTrudeau commentedon Aug 1, 2025
I have done some investigation into what is causing the the menu to disappear after opening. It seems like sometimes on windows the menu opening will cause scroll bars to appear for a split second. The scroll bars appearing will cause the dimensions of the window to change triggering the dimensions listener inside the Menu component which triggers the onDismiss prop. As @lukewis mentioned adding
overflow: "hidden"as a wrapper around the PaperProvider will work, but in my case it was breaking ScrollViews on some screens because the PaperProvider was wrapping my App Component.What I have done is add a view that wraps all content under the Portal inside the Menu component. This view contains the
overflow: "hidden"style. This is working nicely.This is my patch: