[Menu] Fix focus issue#8769
Conversation
Fix condition where item is removed from menu before it is attempted to be used in focus calculation.
oliviertassinari
left a comment
There was a problem hiding this comment.
It would be perfect with a test case, but that's not that important given the master branch is in the end of his cycle life. Thanks for taking the time to open a PR!
| const filteredChildren = this.getFilteredChildren(this.props.children); | ||
| const focusedItem = filteredChildren[focusIndex]; | ||
| if (focusedItem.props.menuItems && focusedItem.props.menuItems.length > 0) { | ||
| if (!!focusedItem && focusedItem.props.menuItems && focusedItem.props.menuItems.length > 0) { |
There was a problem hiding this comment.
Is the following check enough? if (focusedItem &&
There was a problem hiding this comment.
suppose i don't see why not. I sometimes go overboard with ensuring i've got a bool :)
There was a problem hiding this comment.
btw, the minified file translate it to
o&&o.props.menuItems&&o.props.menuItems.length>0
so !! really does not matter :)
|
@zentron Thanks |
|
Thanks @oliviertassinari for the quick merge! |
|
not sure why this has not been published yet ? @oliviertassinari if we follow SEMVER , there should have been one published version after this commit. it has been more than a month :) |
Fix condition where item is removed from menu before it is attempted to be used in focus calculation.
Fix condition where item is removed from menu before it is attempted to be used in focus calculation.
Clicking a menu item triggers an event which can end up causing that item to be removed from the menu. If that is the last item in that menu then the menu disappears, but this focus event triggers and an exception is thrown since
focusedItemis null