Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
fix(menuBar): menuBar should query for uncompiled md-button directives.
Browse files Browse the repository at this point in the history
* Currently we're querying for buttons in the compile function, and we expecting the md-buttons to be already compiled.
But that's not correct, because those will be replaced with a button, after their compile has finished.

Querying for the md-button directive as well solves this.

Fixes #6802.

Closes #8242

Closes #8709
  • Loading branch information
devversion authored and ThomasBurleson committed Jun 11, 2016
1 parent d63e4d0 commit 3654d72
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/components/menuBar/js/menuBarDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ function MenuBarDirective($mdUtil, $mdTheming) {
if (menuEl.nodeName == 'MD-MENU') {
if (!menuEl.hasAttribute('md-position-mode')) {
menuEl.setAttribute('md-position-mode', 'left bottom');
menuEl.querySelector('button,a').setAttribute('role', 'menuitem');

// Since we're in the compile function and actual `md-buttons` are not compiled yet,
// we need to query for possible `md-buttons` as well.
menuEl.querySelector('button, a, md-button').setAttribute('role', 'menuitem');
}
var contentEls = $mdUtil.nodesToArray(menuEl.querySelectorAll('md-menu-content'));
angular.forEach(contentEls, function(contentEl) {
Expand Down
16 changes: 16 additions & 0 deletions src/components/menuBar/menu-bar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,27 @@ describe('material.components.menuBar', function() {
});

describe('ARIA', function() {

it('sets role="menubar" on the menubar', function() {
var menuBar = setup();
var ariaRole = menuBar[0].getAttribute('role');
expect(ariaRole).toBe('menubar');
});

it('should set the role on the menu trigger correctly', inject(function($compile, $rootScope) {
var el = $compile(
'<md-menu-bar>' +
'<md-menu ng-repeat="i in [1, 2, 3]">' +
'<md-button id="triggerButton" ng-click="lastClicked = $index"></md-button>' +
'<md-menu-content></md-menu-content>' +
'</md-menu>' +
'</md-menu-bar>'
)($rootScope);

$rootScope.$digest();

expect(el[0].querySelector('#triggerButton').getAttribute('role')).toBe('menuitem');
}));
});

describe('nested menus', function() {
Expand Down

0 comments on commit 3654d72

Please sign in to comment.