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

Function getChildren

src/components/UncontrolledTabs.jsx:172–261  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

170 }
171
172 function getChildren() {
173 let index = 0;
174 const {
175 children,
176 disabledTabClassName,
177 focus,
178 forceRenderTabPanel,
179 selectedIndex,
180 selectedTabClassName,
181 selectedTabPanelClassName,
182 environment,
183 } = props;
184
185 tabIds.current = tabIds.current || [];
186 let diff = tabIds.current.length - getTabsCount();
187
188 // Add ids if new tabs have been added
189 // Don't bother removing ids, just keep them in case they are added again
190 // This is more efficient, and keeps the uuid counter under control
191 const id = useId();
192 while (diff++ < 0) {
193 tabIds.current.push(`${id}${tabIds.current.length}`);
194 }
195
196 // Map children to dynamically setup refs
197 return deepMap(children, (child) => {
198 let result = child;
199
200 // Clone TabList and Tab components to have refs
201 if (isTabList(child)) {
202 let listIndex = 0;
203
204 // Figure out if the current focus in the DOM is set on a Tab
205 // If it is we should keep the focus on the next selected tab
206 let wasTabFocused = false;
207
208 if (canUseActiveElement == null) {
209 determineCanUseActiveElement(environment);
210 }
211
212 const env =
213 environment || (typeof window !== 'undefined' ? window : undefined);
214 if (canUseActiveElement && env) {
215 wasTabFocused = React.Children.toArray(child.props.children)
216 .filter(isTab)
217 .some((tab, i) => env.document.activeElement === getTab(i));
218 }
219
220 result = cloneElement(child, {
221 children: deepMap(child.props.children, (tab) => {
222 const key = `tabs-${listIndex}`;
223 const selected = selectedIndex === listIndex;
224
225 const props = {
226 tabRef: (node) => {
227 tabNodes.current[key] = node;
228 },
229 id: tabIds.current[listIndex],

Callers 1

UncontrolledTabsFunction · 0.85

Calls 4

getTabsCountFunction · 0.90
deepMapFunction · 0.90
getTabFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…