fix(v2): support rendering of singular tabs (#3823)

* fix(v2): support rendering of singular tabs

Closes #3822

* Update index.tsx

* fix type

Co-authored-by: slorber <lorber.sebastien@gmail.com>
This commit is contained in:
hackerman 2020-11-26 17:12:51 +01:00 committed by GitHub
parent 3166fab307
commit fc4b756ec3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,9 +5,10 @@
* LICENSE file in the root directory of this source tree.
*/
import React, {useState, cloneElement} from 'react';
import React, {useState, cloneElement, Children, ReactElement} from 'react';
import useUserPreferencesContext from '@theme/hooks/useUserPreferencesContext';
import type {Props} from '@theme/Tabs';
import type {Props as TabItemProps} from '@theme/TabItem';
import clsx from 'clsx';
@ -19,18 +20,14 @@ const keys = {
};
function Tabs(props: Props): JSX.Element {
const {
lazy,
block,
children,
defaultValue,
values,
groupId,
className,
} = props;
const {lazy, block, defaultValue, values, groupId, className} = props;
const {tabGroupChoices, setTabGroupChoices} = useUserPreferencesContext();
const [selectedValue, setSelectedValue] = useState(defaultValue);
const children = Children.toArray(props.children) as ReactElement<
TabItemProps
>[];
if (groupId != null) {
const relevantTabGroupChoice = tabGroupChoices[groupId];
if (