MCPcopy
hub / github.com/reactjs/react-tabs / childrenPropType

Function childrenPropType

src/helpers/propTypes.js:4–52  ·  view source on GitHub ↗
(props, propName, componentName)

Source from the content-addressed store, hash-verified

2import { isTab, isTabList, isTabPanel } from './elementTypes';
3
4export function childrenPropType(props, propName, componentName) {
5 let error;
6 let tabsCount = 0;
7 let panelsCount = 0;
8 let tabListFound = false;
9 const listTabs = [];
10 const children = props[propName];
11
12 deepForEach(children, (child) => {
13 if (isTabList(child)) {
14 if (
15 child.props &&
16 child.props.children &&
17 typeof child.props.children === 'object'
18 ) {
19 deepForEach(child.props.children, (listChild) =>
20 listTabs.push(listChild),
21 );
22 }
23
24 if (tabListFound) {
25 error = new Error(
26 "Found multiple 'TabList' components inside 'Tabs'. Only one is allowed.",
27 );
28 }
29 tabListFound = true;
30 }
31 if (isTab(child)) {
32 if (!tabListFound || listTabs.indexOf(child) === -1) {
33 error = new Error(
34 "Found a 'Tab' component outside of the 'TabList' component. 'Tab' components " +
35 "have to be inside the 'TabList' component.",
36 );
37 }
38 tabsCount++;
39 } else if (isTabPanel(child)) {
40 panelsCount++;
41 }
42 });
43
44 if (!error && tabsCount !== panelsCount) {
45 error = new Error(
46 `There should be an equal number of 'Tab' and 'TabPanel' in \`${componentName}\`. ` +
47 `Received ${tabsCount} 'Tab' and ${panelsCount} 'TabPanel'.`,
48 );
49 }
50
51 return error;
52}
53
54export function onSelectPropType(
55 props,

Callers

nothing calls this directly

Calls 1

deepForEachFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…