From 15db15f269a1ac0c54d7e1bcc74a0fa8e6506c40 Mon Sep 17 00:00:00 2001 From: Stefan Urosevic Date: Wed, 30 Oct 2019 18:29:11 -0400 Subject: [PATCH] Fix #130 and #114 -- removing tabs error --- src/TabList.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/TabList.js b/src/TabList.js index 215b67b..e03d715 100644 --- a/src/TabList.js +++ b/src/TabList.js @@ -210,6 +210,15 @@ export default class TabListComponent extends React.Component { // $FlowFixMe scrollToIndex(index: number, rectSide: 'left' | 'right') { + // Scroll to the last element if the index is out of bounds + if(index > this.tabRefs.length - 1) { + index = this.tabRefs.length - 1; + } + // Cancel scrolling if there are no tabs + else if(this.tabRefs.length <= 0) { + return; + } + const tabOffset = this.getTabNode(this.tabRefs[index]).getBoundingClientRect(); const containerOffset = this.listContainer.getBoundingClientRect(); // Cancel scrolling if the tab is visible