Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit e0463c0

Browse files
crisbetokara
authored andcommitted
fix(menu-bar): nested menus not closing when clicking on the toolbar (#9602)
Fixes nested menus not getting closed properly when the user clicks on the toolbar. Fixes #9599.
1 parent 4fb1767 commit e0463c0

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/components/menuBar/js/menuBarController.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,8 @@ MenuBarController.prototype.handleParentClick = function(event) {
249249
var openMenu = this.querySelector('md-menu.md-open');
250250

251251
if (openMenu && !openMenu.contains(event.target)) {
252-
angular.element(openMenu).controller('mdMenu').close();
252+
angular.element(openMenu).controller('mdMenu').close(true, {
253+
closeAll: true
254+
});
253255
}
254256
};
255-
256-
257-
258-
259-
260-

src/components/menuBar/menu-bar.spec.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ describe('material.components.menuBar', function() {
2727

2828
it('should close when clicking on the wrapping toolbar', inject(function($compile, $rootScope, $timeout, $material) {
2929
var ctrl = null;
30+
var menuCtrl = null;
3031
var toolbar = $compile(
3132
'<md-toolbar>' +
3233
'<md-menu-bar>' +
@@ -42,16 +43,22 @@ describe('material.components.menuBar', function() {
4243
attachedMenuElements.push(toolbar); // ensure it gets cleaned up
4344

4445
ctrl = toolbar.find('md-menu-bar').controller('mdMenuBar');
46+
menuCtrl = toolbar.find('md-menu').eq(0).controller('mdMenu');
4547

46-
toolbar.find('md-menu').eq(0).controller('mdMenu').open();
48+
menuCtrl.open();
4749
$timeout.flush();
4850

4951
expect(toolbar).toHaveClass('md-has-open-menu');
52+
spyOn(menuCtrl, 'close').and.callThrough();
53+
5054
toolbar.triggerHandler('click');
5155
$material.flushInterimElement(); // flush out the scroll mask
5256

5357
expect(toolbar).not.toHaveClass('md-has-open-menu');
5458
expect(ctrl.getOpenMenuIndex()).toBe(-1);
59+
expect(menuCtrl.close).toHaveBeenCalledWith(true, {
60+
closeAll: true
61+
});
5562
}));
5663

5764
describe('ARIA', function() {

0 commit comments

Comments
 (0)