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

Commit d412358

Browse files
Splaktarandrewseguin
authored andcommitted
fix(nav-bar): initial disabled state is now respected (#11185)
remove issues with tests that hid this bug improve docs for nav-bar and nav-item add ng-blur to button docs as its used by nav-item Closes #11172. Relates to #10688.
1 parent 19da42d commit d412358

File tree

3 files changed

+49
-39
lines changed

3 files changed

+49
-39
lines changed

src/components/button/button.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,12 @@ function MdAnchorDirective($mdTheming) {
7777
* <md-button class="md-no-focus">No Focus Style</md-button>
7878
* </hljs>
7979
*
80-
* @param {boolean=} md-no-ink If present, disable ripple ink effects.
81-
* @param {expression=} ng-disabled En/Disable based on the expression
82-
* @param {string=} md-ripple-size Overrides the default ripple size logic. Options: `full`, `partial`, `auto`
8380
* @param {string=} aria-label Adds alternative text to button for accessibility, useful for icon buttons.
8481
* If no default text is found, a warning will be logged.
82+
* @param {boolean=} md-no-ink If present, disable ink ripple effects.
83+
* @param {string=} md-ripple-size Overrides the default ripple size logic. Options: `full`, `partial`, `auto`.
84+
* @param {expression=} ng-disabled Disable the button when the expression is truthy.
85+
* @param {expression=} ng-blur Expression evaluated when focus is removed from the button.
8586
*
8687
* @usage
8788
*

src/components/navBar/navBar.js

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,24 @@ angular.module('material.components.navBar', ['material.core'])
2727
* body and no bar pagination.
2828
*
2929
* 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.
3233
*
3334
* 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>.
3642
*
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.
4148
*
4249
* @usage
4350
* <hljs lang="html">
@@ -77,24 +84,24 @@ angular.module('material.components.navBar', ['material.core'])
7784
* @restrict E
7885
*
7986
* @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.
8289
*
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
8491
* to be specified.
8592
*
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
8795
* 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.
8997
* 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
9199
* 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).
95100
* @param {string=} name The name of this link. Used by the nav bar to know
96101
* 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).
98105
*
99106
* @usage
100107
* See `<md-nav-bar>` for usage.
@@ -120,10 +127,10 @@ function MdNavBar($mdAria, $mdTheming) {
120127
template:
121128
'<div class="md-nav-bar">' +
122129
'<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)" ' +
127134
'aria-label="{{ctrl.navBarAriaLabel}}">' +
128135
'</ul>' +
129136
'</nav>' +
@@ -429,7 +436,7 @@ function MdNavItem($mdAria, $$rAF, $mdUtil, $window) {
429436
'<md-button class="_md-nav-button md-accent" ' +
430437
'ng-class="ctrl.getNgClassMap()" ' +
431438
'ng-blur="ctrl.setFocused(false)" ' +
432-
'ng-disabled="ctrl.disabled"' +
439+
'ng-disabled="ctrl.disabled" ' +
433440
'tabindex="-1" ' +
434441
navigationOptions +
435442
navigationAttribute + '>' +
@@ -452,14 +459,16 @@ function MdNavItem($mdAria, $$rAF, $mdUtil, $window) {
452459
'name': '@',
453460
},
454461
link: function(scope, element, attrs, controllers) {
462+
var disconnect;
463+
455464
// When accessing the element's contents synchronously, they
456465
// may not be defined yet because of transclusion. There is a higher
457466
// chance that it will be accessible if we wait one frame.
458-
var disconnect;
459467
$$rAF(function() {
460468
var mdNavItem = controllers[0];
461469
var mdNavBar = controllers[1];
462470
var navButton = angular.element(element[0].querySelector('._md-nav-button'));
471+
463472
if (!mdNavItem.name) {
464473
mdNavItem.name = angular.element(element[0]
465474
.querySelector('._md-nav-button-text')).text().trim();
@@ -470,7 +479,9 @@ function MdNavItem($mdAria, $$rAF, $mdUtil, $window) {
470479
scope.$apply();
471480
});
472481

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) {
474485
var config = {attributes: true, attributeFilter: ['disabled']};
475486
var targetNode = element[0];
476487
var mutationCallback = function(mutationList) {
@@ -487,7 +498,6 @@ function MdNavItem($mdAria, $$rAF, $mdUtil, $window) {
487498
});
488499
}
489500

490-
491501
$mdAria.expectWithText(element, 'aria-label');
492502
});
493503

src/components/navBar/navBar.spec.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,13 @@ describe('mdNavBar', function() {
185185
' tab2' +
186186
' </md-nav-item>' +
187187
'</md-nav-bar>');
188-
$timeout(function(){
189-
var tabCtrl = getTabCtrl('tab2');
190-
expect(tabCtrl.disabled).toBe(true);
191-
});
188+
189+
var tabCtrl = getTabCtrl('tab2');
190+
expect(tabCtrl.disabled).toBe(true);
192191
});
193192

194193
it('should observe the disabled attribute', function () {
195-
$scope.tabDisabled = false;
194+
$scope.$apply('tabDisabled = false');
196195
create('<md-nav-bar>' +
197196
' <md-nav-item md-nav-href="#1" name="tab1">' +
198197
' tab1' +
@@ -201,11 +200,11 @@ describe('mdNavBar', function() {
201200
' tab2' +
202201
' </md-nav-item>' +
203202
'</md-nav-bar>');
204-
$timeout(function(){
205-
var tabCtrl = getTabCtrl('tab2');
206-
expect(tabCtrl.disabled).toBe(false);
207-
$scope.tabDisabled = true;
208-
$scope.$apply();
203+
204+
var tabCtrl = getTabCtrl('tab2');
205+
expect(tabCtrl.disabled).toBe(false);
206+
$scope.$apply('tabDisabled = true');
207+
$timeout(function() {
209208
expect(tabCtrl.disabled).toBe(true);
210209
});
211210
});

0 commit comments

Comments
 (0)