Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure null values are removed from tabs #2805

Merged
merged 4 commits into from
Mar 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion packages/fast-components-react-base/src/tabs/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import React from "react";
import { DisplayNamePrefix } from "../utilities";
import Tab, { TabManagedClasses } from "./tab";
import TabItem from "./tab-item";
import { isNil } from "lodash-es";
import TabPanel, { TabPanelManagedClasses } from "./tab-panel";
import { TabsHandledProps, TabsItem, TabsProps, TabsUnhandledProps } from "./tabs.props";

Expand Down Expand Up @@ -411,7 +412,9 @@ class Tabs extends Foundation<TabsHandledProps, TabsUnhandledProps, TabsState> {
children: React.ReactNode,
slot: TabsSlot | string
): React.ReactNode {
const childBySlot: React.ReactNode = this.withSlot(slot, children);
const childBySlot: React.ReactNode = this.filterChildren(
this.withSlot(slot, children)
);

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

/**
* Need to filter out none truthy results for Preact.
* Can remove if below gets merged in.
* https://github.com/preactjs/preact-compat/pull/461
*/
private filterChildren(nodes: React.ReactNode): React.ReactNode {
if (Array.isArray(nodes)) {
return nodes.filter(Boolean);
} else {
return nodes;
}
}

/**
* Return a tab item if it has a tab and tab panel
*/
Expand Down