Skip to content
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

fix(theme-classic): allow rendering single tab item #8593

Merged
merged 1 commit into from Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -187,4 +187,16 @@ describe('Tabs', () => {
);
}).not.toThrow();
});

it('accepts a single TabItem', () => {
expect(() => {
renderer.create(
<TestProviders>
<Tabs>
<TabItem value="val1">Val1</TabItem>
</Tabs>
</TestProviders>,
);
}).not.toThrow();
});
});
2 changes: 2 additions & 0 deletions packages/docusaurus-theme-classic/src/theme/Tabs/index.tsx
Expand Up @@ -109,6 +109,8 @@ function TabContent({
children,
selectedValue,
}: Props & ReturnType<typeof useTabs>) {
// eslint-disable-next-line no-param-reassign
children = Array.isArray(children) ? children : [children];
if (lazy) {
const selectedTabItem = children.find(
(tabItem) => tabItem.props.value === selectedValue,
Expand Down
4 changes: 3 additions & 1 deletion packages/docusaurus-theme-common/src/utils/tabsUtils.tsx
Expand Up @@ -32,7 +32,9 @@ export interface TabValue {
export interface TabsProps {
readonly lazy?: boolean;
readonly block?: boolean;
readonly children: readonly ReactElement<TabItemProps>[];
readonly children:
| readonly ReactElement<TabItemProps>[]
| ReactElement<TabItemProps>;
readonly defaultValue?: string | null;
readonly values?: readonly TabValue[];
readonly groupId?: string;
Expand Down