From baf809514ed11c97b99881f1494f83fa2c5f1575 Mon Sep 17 00:00:00 2001 From: Kyle Shike Date: Tue, 3 Oct 2023 16:55:02 -0400 Subject: [PATCH] fixes controlled tabs not setting state --- src/Tabs/Tabs.stories.tsx | 53 +++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/src/Tabs/Tabs.stories.tsx b/src/Tabs/Tabs.stories.tsx index 62385cd7..ef4cd865 100644 --- a/src/Tabs/Tabs.stories.tsx +++ b/src/Tabs/Tabs.stories.tsx @@ -1,6 +1,6 @@ import type { Meta, StoryObj } from '@storybook/react'; -import React, { useState } from 'react'; +import React, { useCallback, useState } from 'react'; import { Tabs, Tab } from 'src/Tabs'; @@ -14,35 +14,38 @@ const meta: Meta = { export default meta; type Story = StoryObj; +function ControlledRender() { + const [activeKey, setActiveKey] = useState('one'); + + const handleTabSelect = useCallback((eventKey) => { + alert(`onSelectTab called with tab key ${eventKey}`); + setActiveKey(eventKey); + }, []); + + return ( + + +
Tab Content One
+
+ +
Tab Content Two
+
+ +
Tab Content Three
+
+ +
Tab Content Four
+
+
+ ); +} + export const Controlled: Story = { args: { onSelect: (tabKey) => alert(`onSelect called with tab key ${tabKey}`), id: 'controlled', }, - render: ({ ...args }) => { - const onSelectTab = (tabKey) => { - alert(`onSelectTab called with tab key ${tabKey}`); - }; - - return ( -
- onSelectTab(tabKey)} {...args}> - -
Tab Content One
-
- -
Tab Content Two
-
- -
Tab Content Three
-
- -
Tab Content Four
-
-
-
- ); - }, + render: ControlledRender, }; export const Uncontrolled: Story = {