File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -99,7 +99,7 @@ For more information about controlled and uncontrolled mode of react-tabs see th
9999 } ;
100100
101101 if ( newState . mode === MODE_UNCONTROLLED ) {
102- const maxTabIndex = getTabsCount ( props . children ) - 1 ;
102+ const maxTabIndex = Math . max ( 0 , getTabsCount ( props . children ) - 1 ) ;
103103 let selectedIndex = null ;
104104
105105 if ( state . selectedIndex != null ) {
Original file line number Diff line number Diff line change @@ -541,4 +541,21 @@ describe('<Tabs />', () => {
541541 expect ( firstTab ) . toHaveFocus ( ) ;
542542 assertTabSelected ( 1 ) ;
543543 } ) ;
544+
545+ test ( 'should render first tab once tabs are available' , ( ) => {
546+ const { rerender } = render ( < Tabs > </ Tabs > ) ;
547+
548+ rerender (
549+ < Tabs >
550+ < TabList >
551+ < Tab data-testid = "tab1" > Tab1</ Tab >
552+ < Tab data-testid = "tab2" > Tab2</ Tab >
553+ </ TabList >
554+ < TabPanel data-testid = "panel1" > Hello Tab1</ TabPanel >
555+ < TabPanel data-testid = "panel2" > Hello Tab2</ TabPanel >
556+ </ Tabs > ,
557+ ) ;
558+
559+ assertTabSelected ( 1 ) ;
560+ } ) ;
544561} ) ;
You can’t perform that action at this time.
0 commit comments