Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Close sub-menus when different item at the same level is selected (wh…
Browse files Browse the repository at this point in the history
…ich doesn't have children)

Fixes #12363

Auditors: @petemill

Test Plan:
1. Launch Brave and open the Hamburger / Kabob / Food menu
2. Move mouse to "New Session Tab" and observe menu come up
3. Move mouse down to next item, "New Window"
4. Submenu for "New Session Tab" should now disappear
  • Loading branch information
bsclifton committed Dec 22, 2017
1 parent 9588ac2 commit d8b7364
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion app/renderer/components/common/contextMenu/contextMenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,42 @@ class ContextMenuItem extends ImmutableComponent {

onMouseEnter (e) {
if (this.props.contextMenuItem.has('folderKey')) {
// Context menu item in bookmarks toolbar (bookmarks always have a folder id)
const yAxis = this.getYAxis(e)
windowActions.onShowBookmarkFolderMenu(this.props.contextMenuItem.get('folderKey'), yAxis, null, this.props.submenuIndex)
} else if (this.hasSubmenu) {
// Regular context menu with submenu (ex: hamburger menu)
let openedSubmenuDetails = this.props.contextMenuDetail.get('openedSubmenuDetails')

openedSubmenuDetails = openedSubmenuDetails
? openedSubmenuDetails.splice(this.props.submenuIndex, openedSubmenuDetails.size)
: new Immutable.List()
const yAxis = this.getYAxis(e)

openedSubmenuDetails = openedSubmenuDetails.push(Immutable.fromJS({
y: yAxis,
template: this.submenu
template: this.submenu,
openerSubmenuIndex: this.props.submenuIndex,
openerDataIndex: this.props.dataIndex
}))

windowActions.setContextMenuDetail(this.props.contextMenuDetail.set('openedSubmenuDetails', openedSubmenuDetails))
} else {
// Regular context menu item (no children)
let openedSubmenuDetails = this.props.contextMenuDetail && this.props.contextMenuDetail.get('openedSubmenuDetails')

// If a menu is open, see if the submenuIndex matches
if (openedSubmenuDetails) {
for (let i = 0; i < openedSubmenuDetails.size; i++) {
if (this.props.submenuIndex === openedSubmenuDetails.getIn([i, 'openerSubmenuIndex'])) {
// When index matches, menu should be closed
// User is hovering over a different item at the same level
openedSubmenuDetails = openedSubmenuDetails.remove(i)
windowActions.setContextMenuDetail(this.props.contextMenuDetail.set('openedSubmenuDetails', openedSubmenuDetails))
break
}
}
}
}
}
getLabelForItem (item) {
Expand Down

0 comments on commit d8b7364

Please sign in to comment.