mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-07 05:12:31 +02:00
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:
parent
3166fab307
commit
fc4b756ec3
1 changed files with 7 additions and 10 deletions
|
@ -5,9 +5,10 @@
|
||||||
* LICENSE file in the root directory of this source tree.
|
* 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 useUserPreferencesContext from '@theme/hooks/useUserPreferencesContext';
|
||||||
import type {Props} from '@theme/Tabs';
|
import type {Props} from '@theme/Tabs';
|
||||||
|
import type {Props as TabItemProps} from '@theme/TabItem';
|
||||||
|
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
|
|
||||||
|
@ -19,18 +20,14 @@ const keys = {
|
||||||
};
|
};
|
||||||
|
|
||||||
function Tabs(props: Props): JSX.Element {
|
function Tabs(props: Props): JSX.Element {
|
||||||
const {
|
const {lazy, block, defaultValue, values, groupId, className} = props;
|
||||||
lazy,
|
|
||||||
block,
|
|
||||||
children,
|
|
||||||
defaultValue,
|
|
||||||
values,
|
|
||||||
groupId,
|
|
||||||
className,
|
|
||||||
} = props;
|
|
||||||
const {tabGroupChoices, setTabGroupChoices} = useUserPreferencesContext();
|
const {tabGroupChoices, setTabGroupChoices} = useUserPreferencesContext();
|
||||||
const [selectedValue, setSelectedValue] = useState(defaultValue);
|
const [selectedValue, setSelectedValue] = useState(defaultValue);
|
||||||
|
|
||||||
|
const children = Children.toArray(props.children) as ReactElement<
|
||||||
|
TabItemProps
|
||||||
|
>[];
|
||||||
|
|
||||||
if (groupId != null) {
|
if (groupId != null) {
|
||||||
const relevantTabGroupChoice = tabGroupChoices[groupId];
|
const relevantTabGroupChoice = tabGroupChoices[groupId];
|
||||||
if (
|
if (
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue