Skip to content

Commit 8f5cd84

Browse files
husnimundanez
authored andcommitted
feat: Add support for home and end key on tab list (#246)
1 parent 4455500 commit 8f5cd84

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/components/UncontrolledTabs.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,32 @@ export default class UncontrolledTabs extends Component {
107107
return index;
108108
}
109109

110+
getFirstTab() {
111+
const count = this.getTabsCount();
112+
113+
// Look for non disabled tab from the first tab
114+
for (let i = 0; i < count; i++) {
115+
if (!isTabDisabled(this.getTab(i))) {
116+
return i;
117+
}
118+
}
119+
120+
return null;
121+
}
122+
123+
getLastTab() {
124+
let i = this.getTabsCount();
125+
126+
// Look for non disabled tab from the last tab
127+
while (i--) {
128+
if (!isTabDisabled(this.getTab(i))) {
129+
return i;
130+
}
131+
}
132+
133+
return null;
134+
}
135+
110136
getTabsCount() {
111137
return getTabsCount(this.props.children);
112138
}
@@ -228,6 +254,16 @@ export default class UncontrolledTabs extends Component {
228254
index = this.getNextTab(index);
229255
preventDefault = true;
230256
useSelectedIndex = true;
257+
} else if (e.keyCode === 35) {
258+
// Select last tab (End key)
259+
index = this.getLastTab();
260+
preventDefault = true;
261+
useSelectedIndex = true;
262+
} else if (e.keyCode === 36) {
263+
// Select first tab (Home key)
264+
index = this.getFirstTab();
265+
preventDefault = true;
266+
useSelectedIndex = true;
231267
}
232268

233269
// This prevents scrollbars from moving around

0 commit comments

Comments
 (0)