Skip to content

Commit 34fb19e

Browse files
authored
Merge pull request #268 from dolthub/liuliu/tab-disabled-props
components: add disabled prop to Tab
2 parents 5b1708a + 931f881 commit 34fb19e

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

packages/components/src/Tabs/Tab.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type Props = {
1313
hide?: boolean;
1414
dark?: boolean;
1515
small?: boolean;
16+
disabled?: boolean;
1617
};
1718

1819
export default function Tab(props: Props) {
@@ -36,7 +37,10 @@ export default function Tab(props: Props) {
3637
{props.renderOnlyChild ? (
3738
props.children
3839
) : (
39-
<Btn onClick={() => setActiveTabIndex(props.index)}>
40+
<Btn
41+
onClick={() => setActiveTabIndex(props.index)}
42+
disabled={props.disabled}
43+
>
4044
{props.children}
4145
</Btn>
4246
)}

packages/components/src/__stories__/Tabs.stories.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,25 @@ export const HideLastTab: Story = {
7777
},
7878
};
7979

80+
export const DisableLastTab: Story = {
81+
args: {
82+
initialActiveIndex: 0,
83+
children: [
84+
<TabList key="tabList">
85+
{tabs.map((tab, index) => (
86+
<Tab key={tab} index={index}>
87+
{tab}
88+
</Tab>
89+
))}
90+
<Tab index={2} disabled>
91+
Tab 3
92+
</Tab>
93+
</TabList>,
94+
...panels,
95+
],
96+
},
97+
};
98+
8099
export const TabWithLink: Story = {
81100
args: {
82101
children: [

packages/components/src/__tests__/Tabs.test.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Tab, TabList, TabPanel, Tabs } from "../Tabs";
55
const mocks = [
66
{ tabWord: "zero", panelWord: "Cero" },
77
{ tabWord: "one", panelWord: "Uno" },
8-
{ tabWord: "two", panelWord: "Dos" },
8+
{ tabWord: "two", panelWord: "Dos", disabled: true },
99
{ tabWord: "three", panelWord: "Tres", hide: true },
1010
];
1111

@@ -37,6 +37,7 @@ describe("test Tabs", () => {
3737
key={`tab-${mock.tabWord}`}
3838
aria-label="tab"
3939
hide={mock.hide}
40+
disabled={mock.disabled}
4041
>
4142
{mock.tabWord}
4243
</Tab>
@@ -56,6 +57,8 @@ describe("test Tabs", () => {
5657
if (mocks[i].hide) {
5758
expect(screen.queryByText(mocks[i].panelWord)).not.toBeInTheDocument();
5859
expect(screen.queryByText(mocks[i].tabWord)).not.toBeInTheDocument();
60+
} else if (mocks[i].disabled) {
61+
expect(buttons[i]).toBeDisabled();
5962
} else {
6063
if (i !== 0) {
6164
fireEvent.click(buttons[i]);

0 commit comments

Comments
 (0)