Skip to content

Commit 5c032d0

Browse files
authored
fix: ensure null values are removed from tabs (#2805)
* fix: preact is not rendering tabpanels * checked nodes instead of props * checked if array and otherwise return undefined * updated based on commetns
1 parent c2b75b2 commit 5c032d0

File tree

1 file changed

+17
-1
lines changed
  • packages/fast-components-react-base/src/tabs

1 file changed

+17
-1
lines changed

packages/fast-components-react-base/src/tabs/tabs.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import React from "react";
1414
import { DisplayNamePrefix } from "../utilities";
1515
import Tab, { TabManagedClasses } from "./tab";
1616
import TabItem from "./tab-item";
17+
import { isNil } from "lodash-es";
1718
import TabPanel, { TabPanelManagedClasses } from "./tab-panel";
1819
import { TabsHandledProps, TabsItem, TabsProps, TabsUnhandledProps } from "./tabs.props";
1920

@@ -411,7 +412,9 @@ class Tabs extends Foundation<TabsHandledProps, TabsUnhandledProps, TabsState> {
411412
children: React.ReactNode,
412413
slot: TabsSlot | string
413414
): React.ReactNode {
414-
const childBySlot: React.ReactNode = this.withSlot(slot, children);
415+
const childBySlot: React.ReactNode = this.filterChildren(
416+
this.withSlot(slot, children)
417+
);
415418

416419
return slot !== this.getSlot(TabsSlot.tabItem)
417420
? childBySlot
@@ -423,6 +426,19 @@ class Tabs extends Foundation<TabsHandledProps, TabsUnhandledProps, TabsState> {
423426
);
424427
}
425428

429+
/**
430+
* Need to filter out none truthy results for Preact.
431+
* Can remove if below gets merged in.
432+
* https://github.com/preactjs/preact-compat/pull/461
433+
*/
434+
private filterChildren(nodes: React.ReactNode): React.ReactNode {
435+
if (Array.isArray(nodes)) {
436+
return nodes.filter(Boolean);
437+
} else {
438+
return nodes;
439+
}
440+
}
441+
426442
/**
427443
* Return a tab item if it has a tab and tab panel
428444
*/

0 commit comments

Comments
 (0)