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

Commit

Permalink
fix(mdMenu): improve aria accessability
Browse files Browse the repository at this point in the history
  • Loading branch information
rschmukler committed Jun 11, 2015
1 parent d7bfc86 commit 113ad44
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/components/menu/_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ function MenuDirective($mdMenu) {

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

var menuContainer;
var ctrl = this;
var triggerElement;

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

// Uses the $mdMenu interim element service to open the menu contents
this.open = function openMenu() {
ctrl.isOpen = true;
$element.attr('aria-expanded', 'true');
triggerElement.setAttribute('aria-expanded', 'true');
$mdMenu.show({
mdMenuCtrl: ctrl,
element: menuContainer,
Expand All @@ -199,7 +205,7 @@ function MenuController($mdMenu, $attrs, $element, $scope) {
// Use the $mdMenu interim element service to close the menu contents
this.close = function closeMenu(skipFocus) {
ctrl.isOpen = false;
$element.attr('aria-expanded', 'false');
triggerElement.setAttribute('aria-expanded', 'false');
$mdMenu.hide();

if (!skipFocus) {
Expand Down

0 comments on commit 113ad44

Please sign in to comment.