Skip to content

feat(tabs): set possible to disable panels #436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export namespace TabsProps {
iconId?: FrIconClassName | RiIconClassName;
content: ReactNode;
isDefault?: boolean;
disabled?: boolean;
}[];
selectedTabId?: undefined;
onTabChange?: (params: { tabIndex: number; tab: Uncontrolled["tabs"][number] }) => void;
Expand All @@ -46,6 +47,7 @@ export namespace TabsProps {
tabId: string;
label: ReactNode;
iconId?: FrIconClassName | RiIconClassName;
disabled?: boolean;
}[];
selectedTabId: string;
onTabChange: (tabId: string) => void;
Expand Down Expand Up @@ -156,7 +158,7 @@ export const Tabs = memo(
aria-label={label}
onKeyDownCapture={e => onKeyboardNavigation(e)}
>
{tabs.map(({ label, iconId }, tabIndex) => (
{tabs.map(({ label, iconId, disabled }, tabIndex) => (
<li key={tabIndex} role="presentation">
<button
ref={button => (buttonRefs.current[tabIndex] = button)}
Expand All @@ -171,6 +173,7 @@ export const Tabs = memo(
aria-selected={tabIndex === selectedTabIndex}
aria-controls={getPanelId(tabIndex)}
onClick={onTabClickFactory(tabIndex)}
disabled={disabled}
>
{label}
</button>
Expand Down
10 changes: 7 additions & 3 deletions stories/Tabs.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ In this mode the \`Tab\` component is in charge for swapping the panel content.
tabs={[
{ label: "Tab 1", iconId: "fr-icon-add-line", content: <p>Content of tab1</p> },
{ label: "Tab 2", iconId: "fr-icon-ball-pen-fill", isDefault: true, content: <p>Content of tab2</p> },
{ label: "Tab 3", content: <p>Content of tab3</p> }
{ label: "Tab 3", content: <p>Content of tab3</p> },
{ label: "Tab 4", content: null, disabled: true }
]}
/>
\`\`\`
Expand All @@ -40,6 +41,7 @@ function ControlledTabs() {
{ tabId: "tab1", label: "Tab 1", iconId: "fr-icon-add-line" },
{ tabId: "tab2", label: "Tab 2", iconId: "fr-icon-ball-pen-fill" },
{ tabId: "tab3", label: "Tab 3" },
{ tabId: "tab4", label: "Tab 4", disabled: true },
]}
onTabChange={setSelectedTabId}
>
Expand All @@ -64,7 +66,8 @@ export const Default = getStory({
"iconId": "fr-icon-ball-pen-fill",
"content": <p>Content of tab2</p>
},
{ "label": "Tab 3", "content": <p>Content of tab3</p> }
{ "label": "Tab 3", "content": <p>Content of tab3</p> },
{ "label": "Tab 4", "content": null, disabled: true }
],
"label": "Name of the tabs system",
...logCallbacks(["onTabChange"])
Expand All @@ -79,7 +82,8 @@ export const WithTab2OpenedByDefault = getStory({
"isDefault": true,
"content": <p>Content of tab2</p>
},
{ "label": "Tab 3", "content": <p>Content of tab3</p> }
{ "label": "Tab 3", "content": <p>Content of tab3</p> },
{ "label": "Tab 4", "content": null, "disabled": true }
],
"label": "Name of the tabs system",
...logCallbacks(["onTabChange"])
Expand Down