@@ -27,17 +27,24 @@ angular.module('material.components.navBar', ['material.core'])
27
27
* body and no bar pagination.
28
28
*
29
29
* Because it deals with page navigation, certain routing concepts are built-in.
30
- * Route changes via ng-href, ui-sref, or ng-click events are supported.
31
- * Alternatively, the user could simply watch currentNavItem for changes.
30
+ * Route changes via `ng-href`, `ui-sref`, or `ng-click` events are supported.
31
+ * Alternatively, the user could simply watch the value of `md-selected-nav-item`
32
+ * (`currentNavItem` in the below example) for changes.
32
33
*
33
34
* Accessibility functionality is implemented as a site navigator with a
34
- * listbox, according to
35
- * https://www.w3.org/TR/wai-aria-practices/#Site_Navigator_Tabbed_Style
35
+ * listbox, according to the
36
+ * <a href="https://www.w3.org/TR/2016/WD-wai-aria-practices-1.1-20160317/#Site_Navigator_Tabbed_Style">
37
+ * WAI-ARIA Authoring Practices 1.1 Working Draft from March 2016</a>.
38
+ * We've kept the `role="navigation"` on the `<nav>`, for backwards compatibility, even though
39
+ * it is not required in the
40
+ * <a href="https://www.w3.org/TR/wai-aria-practices/#aria_lh_navigation">
41
+ * latest Working Group Note from December 2017</a>.
36
42
*
37
- * @param {string= } mdSelectedNavItem The name of the current tab; this must
38
- * match the name attribute of `<md-nav-item>`
39
- * @param {boolean= } mdNoInkBar If set to true, the ink bar will be hidden.
40
- * @param {string= } navBarAriaLabel An aria-label for the nav-bar
43
+ * @param {string= } md-selected-nav-item The name of the current tab; this must
44
+ * match the `name` attribute of `<md-nav-item>`.
45
+ * @param {boolean= } md-no-ink-bar If set to true, the ink bar will be hidden.
46
+ * @param {string= } nav-bar-aria-label An `aria-label` applied to the `md-nav-bar`'s listbox
47
+ * for accessibility.
41
48
*
42
49
* @usage
43
50
* <hljs lang="html">
@@ -77,24 +84,24 @@ angular.module('material.components.navBar', ['material.core'])
77
84
* @restrict E
78
85
*
79
86
* @description
80
- * `<md-nav-item>` describes a page navigation link within the `<md-nav-bar>`
81
- * component. It renders an md-button as the actual link.
87
+ * `<md-nav-item>` describes a page navigation link within the `<md-nav-bar>` component.
88
+ * It renders an `< md-button>` as the actual link.
82
89
*
83
- * Exactly one of the mdNavClick, mdNavHref, mdNavSref attributes are required
90
+ * Exactly one of the `md-nav-click`, `md-nav-href`, or `md-nav-sref` attributes are required
84
91
* to be specified.
85
92
*
86
- * @param {Function= } mdNavClick Function which will be called when the
93
+ * @param {string= } aria-label Adds alternative text for accessibility.
94
+ * @param {expression= } md-nav-click Expression which will be evaluated when the
87
95
* link is clicked to change the page. Renders as an `ng-click`.
88
- * @param {string= } mdNavHref url to transition to when this link is clicked.
96
+ * @param {string= } md-nav-href url to transition to when this link is clicked.
89
97
* Renders as an `ng-href`.
90
- * @param {string= } mdNavSref Ui-router state to transition to when this link is
98
+ * @param {string= } md-nav-sref UI-Router state to transition to when this link is
91
99
* clicked. Renders as a `ui-sref`.
92
- * @param {!Object= } srefOpts Ui-router options that are passed to the
93
- * `$state.go()` function. See the [Ui-router documentation for details]
94
- * (https://ui-router.github.io/docs/latest/interfaces/transition.transitionoptions.html).
95
100
* @param {string= } name The name of this link. Used by the nav bar to know
96
101
* which link is currently selected.
97
- * @param {string= } aria-label Adds alternative text for accessibility
102
+ * @param {!object= } sref-opts UI-Router options that are passed to the
103
+ * `$state.go()` function. See the [UI-Router documentation for details]
104
+ * (https://ui-router.github.io/docs/latest/interfaces/transition.transitionoptions.html).
98
105
*
99
106
* @usage
100
107
* See `<md-nav-bar>` for usage.
@@ -120,10 +127,10 @@ function MdNavBar($mdAria, $mdTheming) {
120
127
template :
121
128
'<div class="md-nav-bar">' +
122
129
'<nav role="navigation">' +
123
- '<ul class="_md-nav-bar-list" ng-transclude role="listbox"' +
124
- 'tabindex="0"' +
125
- 'ng-focus="ctrl.onFocus()"' +
126
- 'ng-keydown="ctrl.onKeydown($event)"' +
130
+ '<ul class="_md-nav-bar-list" ng-transclude role="listbox" ' +
131
+ 'tabindex="0" ' +
132
+ 'ng-focus="ctrl.onFocus()" ' +
133
+ 'ng-keydown="ctrl.onKeydown($event)" ' +
127
134
'aria-label="{{ctrl.navBarAriaLabel}}">' +
128
135
'</ul>' +
129
136
'</nav>' +
@@ -429,7 +436,7 @@ function MdNavItem($mdAria, $$rAF, $mdUtil, $window) {
429
436
'<md-button class="_md-nav-button md-accent" ' +
430
437
'ng-class="ctrl.getNgClassMap()" ' +
431
438
'ng-blur="ctrl.setFocused(false)" ' +
432
- 'ng-disabled="ctrl.disabled"' +
439
+ 'ng-disabled="ctrl.disabled" ' +
433
440
'tabindex="-1" ' +
434
441
navigationOptions +
435
442
navigationAttribute + '>' +
@@ -452,14 +459,16 @@ function MdNavItem($mdAria, $$rAF, $mdUtil, $window) {
452
459
'name' : '@' ,
453
460
} ,
454
461
link : function ( scope , element , attrs , controllers ) {
462
+ var disconnect ;
463
+
455
464
// When accessing the element's contents synchronously, they
456
465
// may not be defined yet because of transclusion. There is a higher
457
466
// chance that it will be accessible if we wait one frame.
458
- var disconnect ;
459
467
$$rAF ( function ( ) {
460
468
var mdNavItem = controllers [ 0 ] ;
461
469
var mdNavBar = controllers [ 1 ] ;
462
470
var navButton = angular . element ( element [ 0 ] . querySelector ( '._md-nav-button' ) ) ;
471
+
463
472
if ( ! mdNavItem . name ) {
464
473
mdNavItem . name = angular . element ( element [ 0 ]
465
474
. querySelector ( '._md-nav-button-text' ) ) . text ( ) . trim ( ) ;
@@ -470,7 +479,9 @@ function MdNavItem($mdAria, $$rAF, $mdUtil, $window) {
470
479
scope . $apply ( ) ;
471
480
} ) ;
472
481
473
- if ( 'MutationObserver' in $window ) {
482
+ // Get the disabled attribute value first, then setup observing of value changes
483
+ mdNavItem . disabled = $mdUtil . parseAttributeBoolean ( attrs [ 'disabled' ] , false ) ;
484
+ if ( 'MutationObserver' in $window ) {
474
485
var config = { attributes : true , attributeFilter : [ 'disabled' ] } ;
475
486
var targetNode = element [ 0 ] ;
476
487
var mutationCallback = function ( mutationList ) {
@@ -487,7 +498,6 @@ function MdNavItem($mdAria, $$rAF, $mdUtil, $window) {
487
498
} ) ;
488
499
}
489
500
490
-
491
501
$mdAria . expectWithText ( element , 'aria-label' ) ;
492
502
} ) ;
493
503
0 commit comments