Skip to content

Commit 2551f96

Browse files
committed
feat(tabs): set possible to disable panels
1 parent 3aa529a commit 2551f96

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/Tabs.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export namespace TabsProps {
3535
iconId?: FrIconClassName | RiIconClassName;
3636
content: ReactNode;
3737
isDefault?: boolean;
38+
disabled?: boolean;
3839
}[];
3940
selectedTabId?: undefined;
4041
onTabChange?: (params: { tabIndex: number; tab: Uncontrolled["tabs"][number] }) => void;
@@ -46,6 +47,7 @@ export namespace TabsProps {
4647
tabId: string;
4748
label: ReactNode;
4849
iconId?: FrIconClassName | RiIconClassName;
50+
disabled?: boolean;
4951
}[];
5052
selectedTabId: string;
5153
onTabChange: (tabId: string) => void;
@@ -156,7 +158,7 @@ export const Tabs = memo(
156158
aria-label={label}
157159
onKeyDownCapture={e => onKeyboardNavigation(e)}
158160
>
159-
{tabs.map(({ label, iconId }, tabIndex) => (
161+
{tabs.map(({ label, iconId, disabled }, tabIndex) => (
160162
<li key={tabIndex} role="presentation">
161163
<button
162164
ref={button => (buttonRefs.current[tabIndex] = button)}
@@ -171,6 +173,7 @@ export const Tabs = memo(
171173
aria-selected={tabIndex === selectedTabIndex}
172174
aria-controls={getPanelId(tabIndex)}
173175
onClick={onTabClickFactory(tabIndex)}
176+
disabled={disabled}
174177
>
175178
{label}
176179
</button>

stories/Tabs.stories.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ In this mode the \`Tab\` component is in charge for swapping the panel content.
1818
tabs={[
1919
{ label: "Tab 1", iconId: "fr-icon-add-line", content: <p>Content of tab1</p> },
2020
{ label: "Tab 2", iconId: "fr-icon-ball-pen-fill", isDefault: true, content: <p>Content of tab2</p> },
21-
{ label: "Tab 3", content: <p>Content of tab3</p> }
21+
{ label: "Tab 3", content: <p>Content of tab3</p> },
22+
{ label: "Tab 4", content: null, disabled: true }
2223
]}
2324
/>
2425
\`\`\`
@@ -40,6 +41,7 @@ function ControlledTabs() {
4041
{ tabId: "tab1", label: "Tab 1", iconId: "fr-icon-add-line" },
4142
{ tabId: "tab2", label: "Tab 2", iconId: "fr-icon-ball-pen-fill" },
4243
{ tabId: "tab3", label: "Tab 3" },
44+
{ tabId: "tab4", label: "Tab 4", disabled: true },
4345
]}
4446
onTabChange={setSelectedTabId}
4547
>
@@ -64,7 +66,8 @@ export const Default = getStory({
6466
"iconId": "fr-icon-ball-pen-fill",
6567
"content": <p>Content of tab2</p>
6668
},
67-
{ "label": "Tab 3", "content": <p>Content of tab3</p> }
69+
{ "label": "Tab 3", "content": <p>Content of tab3</p> },
70+
{ "label": "Tab 4", "content": null, disabled: true }
6871
],
6972
"label": "Name of the tabs system",
7073
...logCallbacks(["onTabChange"])
@@ -79,7 +82,8 @@ export const WithTab2OpenedByDefault = getStory({
7982
"isDefault": true,
8083
"content": <p>Content of tab2</p>
8184
},
82-
{ "label": "Tab 3", "content": <p>Content of tab3</p> }
85+
{ "label": "Tab 3", "content": <p>Content of tab3</p> },
86+
{ "label": "Tab 4", "content": null, "disabled": true }
8387
],
8488
"label": "Name of the tabs system",
8589
...logCallbacks(["onTabChange"])

0 commit comments

Comments
 (0)