Skip to content

Commit

Permalink
fix(navbar): fix navbar focus on click
Browse files Browse the repository at this point in the history
add a $timeout that will allow enough time for the click event to
complete so the focus event can properly evaluate

Fixes: angular#11591
  • Loading branch information
codymikol committed Jan 15, 2019
1 parent 9c079aa commit 31ea069
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/components/navBar/navBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,10 +493,11 @@ MdNavBarController.prototype.onKeydown = function(e) {
* @param $$rAF
* @param $mdUtil
* @param $window
* @param $timeout
* @constructor
* @ngInject
*/
function MdNavItem($mdAria, $$rAF, $mdUtil, $window) {
function MdNavItem($mdAria, $$rAF, $mdUtil, $window, $timeout) {
return {
restrict: 'E',
require: ['mdNavItem', '^mdNavBar'],
Expand Down Expand Up @@ -591,7 +592,9 @@ function MdNavItem($mdAria, $$rAF, $mdUtil, $window) {

navButton.on('focus', function() {
if (!mdNavBar.getFocusedTab()) {
mdNavBar.onFocus();
$timeout(function () {
mdNavBar.onFocus();
},200);
}
});

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

0 comments on commit 31ea069

Please sign in to comment.