diff --git a/src/tab/Tab.tsx b/src/tab/Tab.tsx index 7ced92e6..c580f926 100644 --- a/src/tab/Tab.tsx +++ b/src/tab/Tab.tsx @@ -6,15 +6,15 @@ import classNames from "classnames"; import TabHeaderItem from "./header/item/TabHeaderItem"; import List from "../list/List"; -export type TabItem = { - id: string; +export type TabItem = { + id: ID; content: React.ReactNode; icon?: React.ReactNode; isDisabled?: boolean; }; -interface UncontrolledTabProps { - items: TabItem[]; +interface UncontrolledTabProps { + items: TabItem[]; children: React.ReactNode[]; testid?: string; initialActiveTabIndex?: number; @@ -26,16 +26,16 @@ interface UncontrolledTabProps { // and initialActiveTabIndex should be undefined type ControlledTabProps = | { - activeTabIndex: number; - onTabChange: (index: number) => void; - initialActiveTabIndex?: number; - } + activeTabIndex: number; + onTabChange: (index: number) => void; + initialActiveTabIndex?: number; + } | { - activeTabIndex?: number; - onTabChange?: (index: number) => void; - }; + activeTabIndex?: number; + onTabChange?: (index: number) => void; + }; -export type TabProps = ControlledTabProps & UncontrolledTabProps; +export type TabProps = ControlledTabProps & UncontrolledTabProps; function Tab({ testid, @@ -70,9 +70,9 @@ function Tab({
{ children[ - activeTabIndexFromProps === undefined - ? activeTabIndex - : activeTabIndexFromProps + activeTabIndexFromProps === undefined + ? activeTabIndex + : activeTabIndexFromProps ] }
diff --git a/src/tab/header/item/TabHeaderItem.tsx b/src/tab/header/item/TabHeaderItem.tsx index 6cdc0e80..4f65ea9d 100644 --- a/src/tab/header/item/TabHeaderItem.tsx +++ b/src/tab/header/item/TabHeaderItem.tsx @@ -7,7 +7,7 @@ import {TabItem} from "../../Tab"; import ListItem from "../../../list/item/ListItem"; type TabHeaderItemProps = { - tab: TabItem; + tab: TabItem; onClick: (index: number) => void; isActive: boolean; index: number; diff --git a/stories/12-Tab.stories.tsx b/stories/12-Tab.stories.tsx index 4c9a7d62..5969e6a9 100644 --- a/stories/12-Tab.stories.tsx +++ b/stories/12-Tab.stories.tsx @@ -36,7 +36,7 @@ storiesOf("Tab", module).add("Tab", () => (

- + {(state, setState) => (

@@ -45,21 +45,21 @@ storiesOf("Tab", module).add("Tab", () => (

-
{ console.log("tab changed to index: ", index); - setState(index); + setState({index: index}); }}> {[
{"Home tab"}
,
{"Following tab"}
]}