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

Commit 166fb79

Browse files
clshortfusekara
authored andcommitted
fix(tabs): improve tab button focus styling logic (#9916)
Fixes #9039
1 parent f6dedff commit 166fb79

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/components/tabs/js/tabsController.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ angular
55
/**
66
* @ngInject
77
*/
8-
function MdTabsController ($scope, $element, $window, $mdConstant, $mdTabInkRipple,
9-
$mdUtil, $animateCss, $attrs, $compile, $mdTheming) {
8+
function MdTabsController ($scope, $element, $window, $mdConstant, $mdTabInkRipple, $mdUtil,
9+
$animateCss, $attrs, $compile, $mdTheming, $mdInteraction) {
1010
// define private properties
1111
var ctrl = this,
1212
locked = false,
@@ -42,7 +42,7 @@ function MdTabsController ($scope, $element, $window, $mdConstant, $mdTabInkRipp
4242
ctrl.tabs = [];
4343
ctrl.lastSelectedIndex = null;
4444
ctrl.hasFocus = false;
45-
ctrl.lastClick = true;
45+
ctrl.styleTabItemFocus = false;
4646
ctrl.shouldCenterTabs = shouldCenterTabs();
4747
ctrl.tabContentPrefix = 'tab-content-';
4848

@@ -293,7 +293,6 @@ function MdTabsController ($scope, $element, $window, $mdConstant, $mdTabInkRipp
293293
if (!locked) select(ctrl.focusIndex);
294294
break;
295295
}
296-
ctrl.lastClick = false;
297296
}
298297

299298
/**
@@ -304,7 +303,6 @@ function MdTabsController ($scope, $element, $window, $mdConstant, $mdTabInkRipp
304303
*/
305304
function select (index, canSkipClick) {
306305
if (!locked) ctrl.focusIndex = ctrl.selectedIndex = index;
307-
ctrl.lastClick = true;
308306
// skip the click event if noSelectClick is enabled
309307
if (canSkipClick && ctrl.noSelectClick) return;
310308
// nextTick is required to prevent errors in user-defined click events
@@ -431,7 +429,7 @@ function MdTabsController ($scope, $element, $window, $mdConstant, $mdTabInkRipp
431429
isRight: function () { return this.getIndex() > ctrl.selectedIndex; },
432430
shouldRender: function () { return !ctrl.noDisconnect || this.isActive(); },
433431
hasFocus: function () {
434-
return !ctrl.lastClick
432+
return ctrl.styleTabItemFocus
435433
&& ctrl.hasFocus && this.getIndex() === ctrl.focusIndex;
436434
},
437435
id: $mdUtil.nextUid(),
@@ -671,6 +669,7 @@ function MdTabsController ($scope, $element, $window, $mdConstant, $mdTabInkRipp
671669
* issues when attempting to focus an item that is out of view.
672670
*/
673671
function redirectFocus () {
672+
ctrl.styleTabItemFocus = ($mdInteraction.getLastInteractionType() === 'keyboard');
674673
getElements().dummies[ ctrl.focusIndex ].focus();
675674
}
676675

0 commit comments

Comments
 (0)