-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
/
Copy pathTabList.js
43 lines (38 loc) · 1.57 KB
/
TabList.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'use client';
import * as React from 'react';
import PropTypes from 'prop-types';
import Tabs from '@mui/material/Tabs';
import { useTabContext, getTabId, getPanelId } from '../TabContext';
const TabList = React.forwardRef(function TabList(props, ref) {
const { children: childrenProp, ...other } = props;
const context = useTabContext();
if (context === null) {
throw new TypeError('No TabContext provided');
}
const children = React.Children.map(childrenProp, (child) => {
if (!React.isValidElement(child)) {
return null;
}
return React.cloneElement(child, {
// SOMEDAY: `Tabs` will set those themselves
'aria-controls': getPanelId(context, child.props.value),
id: getTabId(context, child.props.value),
});
});
return (
<Tabs {...other} ref={ref} value={context.value}>
{children}
</Tabs>
);
});
TabList.propTypes /* remove-proptypes */ = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
// │ To update them, edit the d.ts file and run `pnpm proptypes`. │
// └─────────────────────────────────────────────────────────────────────┘
/**
* A list of `<Tab />` elements.
*/
children: PropTypes.node,
};
export default TabList;