Skip to content

Commit 69c9729

Browse files
committed
Fixing issue with keyboard navigation
1 parent a276b8a commit 69c9729

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/tabs.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,14 @@ module.exports = React.createClass({
9999
handleKeyDown: function (e) {
100100
if (isTabNode(e.target)) {
101101
var index = this.getSelectedIndex(),
102-
max = this.getTabs().length - 1;
102+
max = this.getTabs().length - 1,
103+
preventDefault = false;
103104

104105
// Select next tab to the left
105106
if (e.keyCode === 37 || e.keyCode === 38) {
106107
index -= 1;
108+
preventDefault = true;
109+
107110
// Wrap back to last tab if index is negative
108111
if (index < 0) {
109112
index = max;
@@ -112,12 +115,19 @@ module.exports = React.createClass({
112115
// Select next tab to the right
113116
else if (e.keyCode === 39 || e.keyCode === 40) {
114117
index += 1;
118+
preventDefault = true;
119+
115120
// Wrap back to first tab if index exceeds max
116121
if (index > max) {
117122
index = 0;
118123
}
119124
}
120125

126+
// This prevents scrollbars from moving around
127+
if (preventDefault) {
128+
e.preventDefault();
129+
}
130+
121131
this.setSelected(index, true);
122132
}
123133
},

0 commit comments

Comments
 (0)