Skip to content
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
15 changes: 9 additions & 6 deletions packages/react-core/src/components/Tabs/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ export enum TabsComponent {
nav = 'nav'
}

type TabElement = React.ReactElement<TabProps, React.JSXElementConstructor<TabProps>>;
type TabsChild = TabElement | boolean | null | undefined;

export interface TabsProps extends Omit<React.HTMLProps<HTMLElement | HTMLDivElement>, 'onSelect'>, OUIAProps {
/** Content rendered inside the tabs component. Must be React.ReactElement<TabProps>[] */
children: React.ReactNode;
/** Content rendered inside the tabs component. Only `Tab` components or expressions resulting in a falsy value are allowed here. */
children: TabsChild | TabsChild[];
/** Additional classes added to the tabs */
className?: string;
/** Tabs background color variant */
Expand Down Expand Up @@ -163,8 +166,8 @@ export class Tabs extends React.Component<TabsProps, TabsState> {
// process any tab content sections outside of the component
if (tabContentRef) {
React.Children.toArray(this.props.children)
.map(child => child as React.ReactElement<TabProps>)
.filter(child => child.props && child.props.tabContentRef && child.props.tabContentRef.current)
.filter((child): child is TabElement => React.isValidElement(child))
.filter(({ props }) => props.tabContentRef && props.tabContentRef.current)
.forEach(child => (child.props.tabContentRef.current.hidden = true));
// most recently selected tabContent
if (tabContentRef.current) {
Expand Down Expand Up @@ -308,8 +311,8 @@ export class Tabs extends React.Component<TabsProps, TabsState> {
uncontrolledActiveKey,
uncontrolledIsExpandedLocal
} = this.state;
const filteredChildren = (React.Children.toArray(children) as React.ReactElement<TabProps>[])
.filter(Boolean)
const filteredChildren = React.Children.toArray(children)
.filter((child): child is TabElement => React.isValidElement(child))
.filter(child => !child.props.isHidden);

const uniqueId = id || getUniqueId();
Expand Down