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

Commit bf6e567

Browse files
kbae00kara
authored andcommitted
fix(tabs): allow right and left arrows to cycle through tabs (#10786)
1 parent 2247248 commit bf6e567

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/components/tabs/js/tabsController.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,9 @@ function MdTabsController ($scope, $element, $window, $mdConstant, $mdTabInkRipp
684684
for (newIndex = index + inc;
685685
ctrl.tabs[ newIndex ] && ctrl.tabs[ newIndex ].scope.disabled;
686686
newIndex += inc) {}
687+
688+
newIndex = (index + inc + ctrl.tabs.length) % ctrl.tabs.length;
689+
687690
if (ctrl.tabs[ newIndex ]) {
688691
ctrl[ key ] = newIndex;
689692
}

src/components/tabs/tabs.spec.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,18 @@ describe('<md-tabs>', function () {
100100
'<md-tab ng-disabled="true"></md-tab>' +
101101
'<md-tab></md-tab>' +
102102
'</md-tabs>');
103+
var ctrl = tabs.controller('mdTabs');
103104
var tabItems = tabs.find('md-tab-item');
104105

105106
expect(tabItems.eq(0)).toBeActiveTab();
106107

107-
// Boundary case, do nothing
108+
// Focus should move to the last tab if left arrow is pressed
108109
triggerKeydown(tabs.find('md-tabs-canvas').eq(0), $mdConstant.KEY_CODE.LEFT_ARROW);
109-
expect(tabItems.eq(0)).toBeActiveTab();
110+
expect(ctrl.getFocusedTabId()).toBe(tabItems.eq(2).attr('id'));
111+
112+
// Focus should move to the first tab if right arrow is pressed
113+
triggerKeydown(tabs.find('md-tabs-canvas').eq(0), $mdConstant.KEY_CODE.RIGHT_ARROW);
114+
expect(ctrl.getFocusedTabId()).toBe(tabItems.eq(0).attr('id'));
110115

111116
// Tab 0 should still be active, but tab 2 focused (skip tab 1 it's disabled)
112117
triggerKeydown(tabs.find('md-tabs-canvas').eq(0), $mdConstant.KEY_CODE.RIGHT_ARROW);
@@ -115,10 +120,6 @@ describe('<md-tabs>', function () {
115120
triggerKeydown(tabs.find('md-tabs-canvas').eq(0), $mdConstant.KEY_CODE.ENTER);
116121
expect(tabItems.eq(2)).toBeActiveTab();
117122

118-
// Boundary case, do nothing
119-
triggerKeydown(tabs.find('md-tabs-canvas').eq(0), $mdConstant.KEY_CODE.RIGHT_ARROW);
120-
expect(tabItems.eq(2)).toBeActiveTab();
121-
122123
triggerKeydown(tabs.find('md-tabs-canvas').eq(0), $mdConstant.KEY_CODE.ENTER);
123124
expect(tabItems.eq(2)).toBeActiveTab();
124125

0 commit comments

Comments
 (0)