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

Commit 113ad44

Browse files
committed
fix(mdMenu): improve aria accessability
1 parent d7bfc86 commit 113ad44

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/components/menu/_menu.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,11 @@ function MenuDirective($mdMenu) {
145145

146146
function compile(templateElement) {
147147
templateElement.addClass('md-menu');
148-
templateElement.children().eq(0).attr('aria-haspopup', 'true');
148+
var triggerElement = templateElement.children()[0];
149+
if (!triggerElement.hasAttribute('ng-click')) {
150+
triggerElement = triggerElement.querySelector('[ng-click]');
151+
}
152+
triggerElement && triggerElement.setAttribute('aria-haspopup', 'true');
149153
if (templateElement.children().length != 2) {
150154
throw Error('Invalid HTML for md-menu. Expected two children elements.');
151155
}
@@ -176,17 +180,19 @@ function MenuController($mdMenu, $attrs, $element, $scope) {
176180

177181
var menuContainer;
178182
var ctrl = this;
183+
var triggerElement;
179184

180185
// Called by our linking fn to provide access to the menu-content
181186
// element removed during link
182187
this.init = function(setMenuContainer) {
183188
menuContainer = setMenuContainer;
189+
triggerElement = $element[0].querySelector('[ng-click]');
184190
};
185191

186192
// Uses the $mdMenu interim element service to open the menu contents
187193
this.open = function openMenu() {
188194
ctrl.isOpen = true;
189-
$element.attr('aria-expanded', 'true');
195+
triggerElement.setAttribute('aria-expanded', 'true');
190196
$mdMenu.show({
191197
mdMenuCtrl: ctrl,
192198
element: menuContainer,
@@ -199,7 +205,7 @@ function MenuController($mdMenu, $attrs, $element, $scope) {
199205
// Use the $mdMenu interim element service to close the menu contents
200206
this.close = function closeMenu(skipFocus) {
201207
ctrl.isOpen = false;
202-
$element.attr('aria-expanded', 'false');
208+
triggerElement.setAttribute('aria-expanded', 'false');
203209
$mdMenu.hide();
204210

205211
if (!skipFocus) {

0 commit comments

Comments
 (0)