Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/components/navBar/navBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,9 @@ function MdNavBar($mdAria, $mdTheming) {

/**
* Controller for the nav-bar component.
*
* TODO update this with a link to tablist when that implementation gets merged.
* Accessibility functionality is implemented as a site navigator with a listbox, according to
* https://www.w3.org/TR/wai-aria-practices/#Site_Navigator_Tabbed_Style.
* Accessibility functionality is implemented as a tablist
* (https://www.w3.org/TR/wai-aria-1.0/complete#tablist) and
* tabs (https://www.w3.org/TR/wai-aria-1.0/complete#tab).
*
* @param {!angular.JQLite} $element
* @param {!angular.Scope} $scope
Expand Down Expand Up @@ -196,6 +195,7 @@ MdNavBarController.prototype._initTabs = function() {
MdNavBarController.prototype._updateTabs = function(newValue, oldValue) {
var self = this;
var tabs = this._getTabs();
var sameTab = newValue === oldValue;

// this._getTabs can return null if nav-bar has not yet been initialized
if (!tabs) return;
Expand All @@ -217,6 +217,11 @@ MdNavBarController.prototype._updateTabs = function(newValue, oldValue) {

this._$timeout(function() {
self._updateInkBarStyles(newTab, newIndex, oldIndex);
// Don't change focus when there is no newTab, the new and old tabs are the same, or when
// called from MdNavBarController._initTabs() which would have no oldTab defined.
if (newTab && oldTab && !sameTab) {
self._moveFocus(oldTab, newTab);
}
});
};

Expand Down Expand Up @@ -596,6 +601,9 @@ function MdNavItem($mdAria, $$rAF, $mdUtil, $window) {
});

navButton.on('click', function() {
// This triggers a watcher on mdNavBar.mdSelectedNavItem which calls
// MdNavBarController._updateTabs() after a $timeout. That function calls
// MdNavItemController.setSelected() for the old tab with false and the new tab with true.
mdNavBar.mdSelectedNavItem = mdNavItem.name;
scope.$apply();
});
Expand Down
5 changes: 0 additions & 5 deletions src/components/navBar/navBar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ $md-nav-bar-height: 48px;
&:focus {
outline: none;
}

&:hover {
background-color: inherit;
}

}

md-nav-ink-bar {
Expand Down
11 changes: 11 additions & 0 deletions src/components/navBar/navBar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,17 @@ describe('mdNavBar', function() {
expect($scope.selectedTabRoute).toBe('tab2');
});

it('should add the md-focused class when focused', function () {
$scope.selectedTabRoute = 'tab1';
createTabs();
var tab2Ctrl = getTabCtrl('tab2');
angular.element(tab2Ctrl.getButtonEl()).triggerHandler('focus');
angular.element(tab2Ctrl.getButtonEl()).triggerHandler('click');
$scope.$apply();
$timeout.flush();
expect(tab2Ctrl.getButtonEl().classList.contains('md-focused')).toBe(true);
});

it('adds ui-sref-opts attribute to nav item when sref-opts attribute is ' +
'defined', function() {
create(
Expand Down