diff --git a/src/components/Tabs.js b/src/components/Tabs.js index b3e6fdadb..2baf5f19f 100644 --- a/src/components/Tabs.js +++ b/src/components/Tabs.js @@ -99,7 +99,7 @@ For more information about controlled and uncontrolled mode of react-tabs see th }; if (newState.mode === MODE_UNCONTROLLED) { - const maxTabIndex = getTabsCount(props.children) - 1; + const maxTabIndex = Math.max(0, getTabsCount(props.children) - 1); let selectedIndex = null; if (state.selectedIndex != null) { diff --git a/src/components/__tests__/Tabs-test.js b/src/components/__tests__/Tabs-test.js index 1b7173777..66e86f726 100644 --- a/src/components/__tests__/Tabs-test.js +++ b/src/components/__tests__/Tabs-test.js @@ -541,4 +541,21 @@ describe('', () => { expect(firstTab).toHaveFocus(); assertTabSelected(1); }); + + test('should render first tab once tabs are available', () => { + const { rerender } = render(); + + rerender( + + + Tab1 + Tab2 + + Hello Tab1 + Hello Tab2 + , + ); + + assertTabSelected(1); + }); });