Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for home and end key on tab list #246

Merged
merged 1 commit into from
May 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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