in src/components/UncontrolledTabs.js [165:260]
function getChildren() {
let index = 0;
const {
children,
disabledTabClassName,
focus,
forceRenderTabPanel,
selectedIndex,
selectedTabClassName,
selectedTabPanelClassName,
environment,
} = props;
tabIds.current = tabIds.current || [];
panelIds.current = panelIds.current || [];
let diff = tabIds.current.length - getTabsCount();
// Add ids if new tabs have been added
// Don't bother removing ids, just keep them in case they are added again
// This is more efficient, and keeps the uuid counter under control
while (diff++ < 0) {
tabIds.current.push(uuid());
panelIds.current.push(uuid());
}
// Map children to dynamically setup refs
return deepMap(children, (child) => {
let result = child;
// Clone TabList and Tab components to have refs
if (isTabList(child)) {
let listIndex = 0;
// Figure out if the current focus in the DOM is set on a Tab
// If it is we should keep the focus on the next selected tab
let wasTabFocused = false;
if (canUseActiveElement == null) {
determineCanUseActiveElement(environment);
}
if (canUseActiveElement) {
wasTabFocused = React.Children.toArray(child.props.children)
.filter(isTab)
.some((tab, i) => {
const env =
environment ||
(typeof window !== 'undefined' ? window : undefined);
return env && env.document.activeElement === getTab(i);
});
}
result = cloneElement(child, {
children: deepMap(child.props.children, (tab) => {
const key = `tabs-${listIndex}`;
const selected = selectedIndex === listIndex;
const props = {
tabRef: (node) => {
tabNodes.current[key] = node;
},
id: tabIds.current[listIndex],
panelId: panelIds.current[listIndex],
selected,
focus: selected && (focus || wasTabFocused),
};
if (selectedTabClassName)
props.selectedClassName = selectedTabClassName;
if (disabledTabClassName)
props.disabledClassName = disabledTabClassName;
listIndex++;
return cloneElement(tab, props);
}),
});
} else if (isTabPanel(child)) {
const props = {
id: panelIds.current[index],
tabId: tabIds.current[index],
selected: selectedIndex === index,
};
if (forceRenderTabPanel) props.forceRender = forceRenderTabPanel;
if (selectedTabPanelClassName)
props.selectedClassName = selectedTabPanelClassName;
index++;
result = cloneElement(child, props);
}
return result;
});
}