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

Commit b7b1d01

Browse files
clshortfusetinayuangao
authored andcommitted
fix(navBar): automatically add aria-label for navBarItem (#10219)
NavBarItems should populate aria-label attribute automatically * Inject $mdAria into navBarItem controller * Use text content from element to populate aria-label during postLink * Create new spec tests Fixes #10110
1 parent 3556d57 commit b7b1d01

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/components/navBar/navBar.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ angular.module('material.components.navBar', ['material.core'])
9494
* (https://ui-router.github.io/docs/latest/interfaces/transition.transitionoptions.html).
9595
* @param {string=} name The name of this link. Used by the nav bar to know
9696
* which link is currently selected.
97+
* @param {string=} aria-label Adds alternative text for accessibility
9798
*
9899
* @usage
99100
* See `<md-nav-bar>` for usage.
@@ -387,7 +388,7 @@ MdNavBarController.prototype.onKeydown = function(e) {
387388
/**
388389
* @ngInject
389390
*/
390-
function MdNavItem($$rAF) {
391+
function MdNavItem($mdAria, $$rAF) {
391392
return {
392393
restrict: 'E',
393394
require: ['mdNavItem', '^mdNavBar'],
@@ -467,6 +468,8 @@ function MdNavItem($$rAF) {
467468
mdNavBar.mdSelectedNavItem = mdNavItem.name;
468469
scope.$apply();
469470
});
471+
472+
$mdAria.expectWithText(element, 'aria-label');
470473
});
471474
}
472475
};

src/components/navBar/navBar.spec.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('mdNavBar', function() {
4242
' <md-nav-item md-nav-href="#2" name="tab2">' +
4343
' tab2' +
4444
' </md-nav-item>' +
45-
' <md-nav-item md-nav-href="#3" name="tab3">' +
45+
' <md-nav-item md-nav-href="#3" name="tab3" aria-label="foo">' +
4646
' tab3' +
4747
' </md-nav-item>' +
4848
'</md-nav-bar>');
@@ -328,6 +328,17 @@ describe('mdNavBar', function() {
328328

329329
expect(tab2Ctrl.getButtonEl().click).toHaveBeenCalled();
330330
});
331+
332+
it('automatically adds label to nav items', function() {
333+
createTabs();
334+
expect(getTab('tab1').parent().attr('aria-label')).toBe('tab1');
335+
expect(getTab('tab2').parent().attr('aria-label')).toBe('tab2');
336+
});
337+
338+
it('does not change aria-label on nav items', function() {
339+
createTabs();
340+
expect(getTab('tab3').parent().attr('aria-label')).toBe('foo');
341+
});
331342
});
332343

333344
function getTab(tabName) {

0 commit comments

Comments
 (0)