[Menu] Entire App crashes if no MenuItems exist
See original GitHub issueDescribe the bug When selecting the Menu and no items are rendered, the entire app crashes
Expected Behavior Dropdown should not open (since no items) and definitely not crash the app
To Reproduce https://codesandbox.io/s/great-volhard-ozr5l
Suggested solution(s)
- Don’t open the menu when no menu items are present
- Check before focusing to see if the element exist (this is where the error throws) https://github.com/chakra-ui/chakra-ui/blob/14b0ad5fb5c821032168793406d5a0c2c3cfc849/packages/chakra-ui/src/Menu/index.js#L91
I can make the PR, let me know which way is best
Desktop (please complete the following information):
- OS - MacOS Catalina
- Browser - Chrome
- Version (“@chakra-ui/core”: “^0.5.2”)
Additional context Usually the MenuList component would have children (MenuItem), in the event where the list is populated by data from an api and the server is down, the app should still work, with data that is stored locally. In the example below, the menu is usually populated with a list of schools to choose from, however since the server is down, the list would be empty.
<MenuList placement="bottom-start">
{schools.map(a => (
<MenuItem
fontSize="sm"
key={a.id}
onClick={() => selectSchool(a.id)}
>
{a.name}
</MenuItem>
))}
</MenuList>
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
android option menu crashes - Stack Overflow
When I click on the menu, the 2 points "About" and "Help" appears. But when I click on one of these entries, the...
Read more >Working with the AppBar - Android Developers
The top app bar provides a consistent place along the top of your app window for displaying information and actions from the current...
Read more >If an app freezes or quits unexpectedly on Mac - Apple Support
Choose Apple menu > Force Quit, select the app in the dialog that appears, then click Force Quit. If the app quit, reopen...
Read more >Onclick Listener Crashes app (Example) - Treehouse
Every time i add the onclick listener code shown in the video the app crashes when I try to run it. there is...
Read more >bizarre OutOfBoundsException on Menuitem.Remove only on ...
Works fine on Mac, throws an OutOfBoundsException on Windows, when j= 0. ... am trying to tell you that a test app containing...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @iRoachie, I’ve just fixed this bug. Ideally, you might not want to render the MenuList if
schools
array is empty.I’ll release a patch shortly for this.
Thanks, that’s what I ended up doing