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

This commit is contained in:
Joshua Chen 2023-02-02 06:19:31 -05:00 committed by GitHub
parent 2f02beebe2
commit 1bff83cacc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 1 deletions

View file

@ -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();
});
});

View file

@ -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,

View file

@ -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;