Skip to content

Commit 883983c

Browse files
Josh-Cenaslorber
authored andcommitted
fix(theme-classic): allow rendering single tab item (#8593)
1 parent 2bdd27a commit 883983c

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

packages/docusaurus-theme-classic/src/theme/Tabs/__tests__/index.test.tsx

+12
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,16 @@ describe('Tabs', () => {
187187
);
188188
}).not.toThrow();
189189
});
190+
191+
it('accepts a single TabItem', () => {
192+
expect(() => {
193+
renderer.create(
194+
<TestProviders>
195+
<Tabs>
196+
<TabItem value="val1">Val1</TabItem>
197+
</Tabs>
198+
</TestProviders>,
199+
);
200+
}).not.toThrow();
201+
});
190202
});

packages/docusaurus-theme-classic/src/theme/Tabs/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ function TabContent({
109109
children,
110110
selectedValue,
111111
}: Props & ReturnType<typeof useTabs>) {
112+
// eslint-disable-next-line no-param-reassign
113+
children = Array.isArray(children) ? children : [children];
112114
if (lazy) {
113115
const selectedTabItem = children.find(
114116
(tabItem) => tabItem.props.value === selectedValue,

packages/docusaurus-theme-common/src/utils/tabsUtils.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ export interface TabValue {
3232
export interface TabsProps {
3333
readonly lazy?: boolean;
3434
readonly block?: boolean;
35-
readonly children: readonly ReactElement<TabItemProps>[];
35+
readonly children:
36+
| readonly ReactElement<TabItemProps>[]
37+
| ReactElement<TabItemProps>;
3638
readonly defaultValue?: string | null;
3739
readonly values?: readonly TabValue[];
3840
readonly groupId?: string;

0 commit comments

Comments
 (0)