Skip to content

Commit

Permalink
fix(v2): support rendering of singular tabs (#3823)
Browse files Browse the repository at this point in the history
* fix(v2): support rendering of singular tabs

Closes #3822

* Update index.tsx

* fix type

Co-authored-by: slorber <[email protected]>
  • Loading branch information
aeneasr and slorber authored Nov 26, 2020
1 parent 3166fab commit fc4b756
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions packages/docusaurus-theme-classic/src/theme/Tabs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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 (
Expand Down

0 comments on commit fc4b756

Please sign in to comment.