Skip to content

Commit f553213

Browse files
committed
feat(tabs): allow initial tab configuration
1 parent 64dab0e commit f553213

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/tabs/StatefulTabs.jsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@ import React, { useState } from 'react';
22
import PropTypes from 'prop-types';
33
import { Tabs } from './Tabs';
44

5-
export function StatefulTabs({ activeTab: _, tabs, ...props }) {
6-
const { getSelected, select } = useTabs(tabs);
5+
export function StatefulTabs({ initialTab, activeTab: _, tabs, ...props }) {
6+
const { getSelected, select } = useTabs(tabs, initialTab);
77

88
return <Tabs tabs={tabs} {...props} activeTab={getSelected()} onSelect={select} />;
99
}
1010

1111
StatefulTabs.propTypes = {
1212
activeTab: PropTypes.any,
1313
tabs: PropTypes.arrayOf(PropTypes.object),
14+
initialTab: PropTypes.number,
1415
};
1516

16-
function useTabs(tabs) {
17-
const [activeTab, setActiveTab] = useState(0);
17+
function useTabs(tabs, initialTab) {
18+
const [activeTab, setActiveTab] = useState(initialTab < tabs.length ? initialTab : 0);
1819

1920
return {
2021
getSelected() {

0 commit comments

Comments
 (0)