From efd697290ed3658d9b2a8cc3b1206c9aca50c9a3 Mon Sep 17 00:00:00 2001 From: Bohdan Shulha Date: Mon, 4 Nov 2019 00:16:16 +0200 Subject: [PATCH 1/2] fix(v2): allow to create tabs with only one item It was not possible to have tabs containing only one tab item, so the code below crashed ``` Tab content ``` --- packages/docusaurus-theme-classic/src/theme/Tabs/index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/docusaurus-theme-classic/src/theme/Tabs/index.js b/packages/docusaurus-theme-classic/src/theme/Tabs/index.js index d1f9933759b2..a527b6ac4df8 100644 --- a/packages/docusaurus-theme-classic/src/theme/Tabs/index.js +++ b/packages/docusaurus-theme-classic/src/theme/Tabs/index.js @@ -13,6 +13,10 @@ function Tabs(props) { const {block, children, defaultValue, values} = props; const [selectedValue, setSelectedValue] = useState(defaultValue); + const selectedTabItem = React.Children.toArray(children).filter( + child => child.props.value === selectedValue, + )[0]; + return (
-
- {children.filter(child => child.props.value === selectedValue)[0]} -
+
{selectedTabItem}
); } From 2a749f2edb024cfda049032a386715bc447b3d14 Mon Sep 17 00:00:00 2001 From: Yangshun Tay Date: Mon, 4 Nov 2019 08:50:27 +0800 Subject: [PATCH 2/2] Update index.js --- packages/docusaurus-theme-classic/src/theme/Tabs/index.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/docusaurus-theme-classic/src/theme/Tabs/index.js b/packages/docusaurus-theme-classic/src/theme/Tabs/index.js index a527b6ac4df8..a2b9d883fd97 100644 --- a/packages/docusaurus-theme-classic/src/theme/Tabs/index.js +++ b/packages/docusaurus-theme-classic/src/theme/Tabs/index.js @@ -13,10 +13,6 @@ function Tabs(props) { const {block, children, defaultValue, values} = props; const [selectedValue, setSelectedValue] = useState(defaultValue); - const selectedTabItem = React.Children.toArray(children).filter( - child => child.props.value === selectedValue, - )[0]; - return (
    ))}
-
{selectedTabItem}
+
+ {[...children].filter(child => child.props.value === selectedValue)[0]} +
); }