From c5bd15cac8d0ac94021ce5d6478661991c40d7d0 Mon Sep 17 00:00:00 2001 From: Sebastian Mattar Date: Mon, 1 Apr 2019 21:25:06 +0200 Subject: [PATCH] Fixed Pivot to show the correct PivotItem (#8501) when JSX expressions are used --- .../Fix-PivotItems_2019-03-27-19-38.json | 11 ++ .../src/components/Pivot/Pivot.base.tsx | 7 +- .../src/components/Pivot/Pivot.test.tsx | 11 +- .../Pivot/__snapshots__/Pivot.test.tsx.snap | 163 +++++++++++++++++- 4 files changed, 178 insertions(+), 14 deletions(-) create mode 100644 common/changes/office-ui-fabric-react/Fix-PivotItems_2019-03-27-19-38.json diff --git a/common/changes/office-ui-fabric-react/Fix-PivotItems_2019-03-27-19-38.json b/common/changes/office-ui-fabric-react/Fix-PivotItems_2019-03-27-19-38.json new file mode 100644 index 00000000000000..b30964b95adf04 --- /dev/null +++ b/common/changes/office-ui-fabric-react/Fix-PivotItems_2019-03-27-19-38.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "office-ui-fabric-react", + "comment": "Fixed a problem with Pivot showing the wrong PivotItems when using JSX expressions. Extended the test case", + "type": "patch" + } + ], + "packageName": "office-ui-fabric-react", + "email": "sebastian.mattar@gmail.com" +} \ No newline at end of file diff --git a/packages/office-ui-fabric-react/src/components/Pivot/Pivot.base.tsx b/packages/office-ui-fabric-react/src/components/Pivot/Pivot.base.tsx index cba67dca63de4f..67a25d04738817 100644 --- a/packages/office-ui-fabric-react/src/components/Pivot/Pivot.base.tsx +++ b/packages/office-ui-fabric-react/src/components/Pivot/Pivot.base.tsx @@ -207,12 +207,7 @@ export class PivotBase extends BaseComponent { keyToTabIdMapping: {} }; - React.Children.map(props.children, (child: any, index: number) => { - // skip empty JSX expressions - if (!child) { - return; - } - + React.Children.map(React.Children.toArray(props.children), (child: any, index: number) => { if (typeof child === 'object' && child.type === PivotItemType) { const pivotItem = child as PivotItem; const { linkText, ...pivotItemProps } = pivotItem.props; diff --git a/packages/office-ui-fabric-react/src/components/Pivot/Pivot.test.tsx b/packages/office-ui-fabric-react/src/components/Pivot/Pivot.test.tsx index f82f8039366857..99fd13217b158d 100644 --- a/packages/office-ui-fabric-react/src/components/Pivot/Pivot.test.tsx +++ b/packages/office-ui-fabric-react/src/components/Pivot/Pivot.test.tsx @@ -24,9 +24,14 @@ describe('Pivot', () => { it('supports JSX expressions', () => { const component = renderer.create( - - - {false && } + + +
This is item 1
+
+ {false && } + +
This is Item 3
+
); const tree = component.toJSON(); diff --git a/packages/office-ui-fabric-react/src/components/Pivot/__snapshots__/Pivot.test.tsx.snap b/packages/office-ui-fabric-react/src/components/Pivot/__snapshots__/Pivot.test.tsx.snap index f1ace6341166c3..f3494647ef6052 100644 --- a/packages/office-ui-fabric-react/src/components/Pivot/__snapshots__/Pivot.test.tsx.snap +++ b/packages/office-ui-fabric-react/src/components/Pivot/__snapshots__/Pivot.test.tsx.snap @@ -2733,6 +2733,155 @@ exports[`Pivot supports JSX expressions 1`] = ` } role="tablist" > +