Skip to content

Commit

Permalink
feat: Add support for home and end key on tab list (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
husnimun authored and danez committed Jun 16, 2018
1 parent 4455500 commit 8f5cd84
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/components/UncontrolledTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,32 @@ export default class UncontrolledTabs extends Component {
return index;
}

getFirstTab() {
const count = this.getTabsCount();

// Look for non disabled tab from the first tab
for (let i = 0; i < count; i++) {
if (!isTabDisabled(this.getTab(i))) {
return i;
}
}

return null;
}

getLastTab() {
let i = this.getTabsCount();

// Look for non disabled tab from the last tab
while (i--) {
if (!isTabDisabled(this.getTab(i))) {
return i;
}
}

return null;
}

getTabsCount() {
return getTabsCount(this.props.children);
}
Expand Down Expand Up @@ -228,6 +254,16 @@ export default class UncontrolledTabs extends Component {
index = this.getNextTab(index);
preventDefault = true;
useSelectedIndex = true;
} else if (e.keyCode === 35) {
// Select last tab (End key)
index = this.getLastTab();
preventDefault = true;
useSelectedIndex = true;
} else if (e.keyCode === 36) {
// Select first tab (Home key)
index = this.getFirstTab();
preventDefault = true;
useSelectedIndex = true;
}

// This prevents scrollbars from moving around
Expand Down

0 comments on commit 8f5cd84

Please sign in to comment.