Skip to content

Commit

Permalink
Refactor TabTrigger component useContext usage
Browse files Browse the repository at this point in the history
  • Loading branch information
kotAPI committed Nov 3, 2024
1 parent e9f847f commit 1694f8e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/components/ui/Tabs/fragments/TabTrigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type TabTriggerProps = {

const TabTrigger = ({ tab, className = '', ...props }: TabTriggerProps) => {
// use context
const { tabs, previousTab, nextTab, activeTab, setActiveTab, rootClass } = useContext(TabsRootContext);
const { previousTab, nextTab, activeTab, setActiveTab, rootClass } = useContext(TabsRootContext);
const ref = useRef<HTMLButtonElement>(null);

const isActive = activeTab === tab.value;
Expand Down Expand Up @@ -54,6 +54,7 @@ const TabTrigger = ({ tab, className = '', ...props }: TabTriggerProps) => {
onFocus={() => handleFocus(tab)}
tabIndex={isActive ? 0 : -1}
data-rad-ui-batch-element

>
{tab.label}
</button>
Expand Down
30 changes: 30 additions & 0 deletions src/components/ui/Tabs/stories/Tabs.stories.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Tabs from '../Tabs';
import SandboxEditor from '~/components/tools/SandboxEditor/SandboxEditor';

import Button from '~/components/ui/Button/Button';

// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
export default {
title: 'WIP/Tabs',
Expand Down Expand Up @@ -37,3 +39,31 @@ export const All = {
]
}
};

const TabInTabOutTemplate = (args) => {
return <SandboxEditor>
<Button>Click me</Button>
<Tabs {...args} />
<Button>Click me</Button>
</SandboxEditor>;
};

export const TabInTabOut = TabInTabOutTemplate.bind({});
TabInTabOut.args = {
tabs: [{
label: 'Tabbing In',
value: 'tab_in_1',
content: 'Focus on the first button, press tab to move to the Tab component, it tabs into the selected tab. '

},
{
label: <div className='flex items-center space-x-2'> <span>Tab Out</span> <ArrowIcon/></div>,
value: 'tab_out_2',
content: <div className='text-gray-1000'>
Once you tab out of the Tab component, you will be focused on the second button.
</div>
}

]

};

0 comments on commit 1694f8e

Please sign in to comment.