我想在“垂直标签”中使用“材质”用户界面“固定标签”。我包括了“固定选项卡”,它看起来很好。但是,该功能似乎无法正常工作。
这是沙箱link
步骤
问题 -单击日期时,将转到“垂直”标签,而不是“固定”标签。
JS文件如下。
import React from 'react';
import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';
import { makeStyles } from '@material-ui/core/styles';
import Tabs from '@material-ui/core/Tabs';
import Tab from '@material-ui/core/Tab';
import Box from '@material-ui/core/Box';
import TableContainer from '@material-ui/core/TableContainer';
import Paper from '@material-ui/core/Paper';
import Typography from '@material-ui/core/Typography';
import Button from '@material-ui/core/Button';
import Grid from '@material-ui/core/Grid';
import AppBar from '@material-ui/core/AppBar';
function TabPanel(props) {
const { children, value, index, ...other } = props;
return (
<Typography
component="div"
role="tabpanel"
hidden={value !== index}
id={`vertical-tabpanel-${index}`}
aria-labelledby={`vertical-tab-${index}`}
{...other}
>
{value === index && <Box p={3}>{children}</Box>}
</Typography>
);
}
TabPanel.propTypes = {
children: PropTypes.node,
index: PropTypes.any.isRequired,
value: PropTypes.any.isRequired,
};
function a11yProps(index) {
return {
id: `vertical-tab-${index}`,
'aria-controls': `vertical-tabpanel-${index}`,
};
}
/*tab section*/
function TabPanel2(props) {
const { children, value, index, ...other } = props;
return (
<Typography
component="div"
role="tabpanel"
hidden={value !== index}
id={`scrollable-auto-tabpanel-${index}`}
aria-labelledby={`scrollable-auto-tab-${index}`}
{...other}
>
{value === index && <Box p={3}>{children}</Box>}
</Typography>
);
}
function a11yProps2(index) {
return {
id: `scrollable-auto-tab-${index}`,
'aria-controls': `scrollable-auto-tabpanel-${index}`,
};
}
TabPanel2.propTypes = {
children: PropTypes.node,
index: PropTypes.any.isRequired,
value: PropTypes.any.isRequired,
};
const useStyles2 = makeStyles(theme => ({
root: {
flexGrow: 1,
width: '100%',
backgroundColor: theme.palette.background.paper,
},
}));
/*tab section*/
const useStyles = makeStyles(theme => ({
root: {
flexGrow: 1,
backgroundColor: theme.palette.background.paper,
display: 'flex',
height: 224,
},
tabs: {
borderRight: `1px solid ${theme.palette.divider}`,
},
}));
/* component 2*/
export default function VerticalTabs() {
const classes = useStyles();
const classes2 = useStyles2();
const [value, setValue] = React.useState(0);
const handleChange = (event, newValue) => {
setValue(newValue);
};
return (
<div className={classes.root} >
<span> </span>
<Box component="span" m={1}>
<Button />
</Box>
<Tabs
orientation="vertical"
variant="scrollable"
value={value}
onChange={handleChange}
aria-label="Vertical tabs example"
className={classes.tabs}
>
<Tab label="HOUSE DETAILS" {...a11yProps(0)} />
<Tab label="DAILY TASKS" {...a11yProps(0)} />
<Tab label="WEEKLY TASKS" {...a11yProps(0)} />
<Tab label="OTHER TASKS" {...a11yProps(0)} />
htr
</Tabs>
<TabPanel value={value} index={0}>
House Details
<Grid container spacing={3}>
<Grid item xs={12} >
<Paper className={classes.paper}><ul>
<li>The light in Karimi must ne left on or dimmed in order to illuminate the common areas.</li>
<li>The light in Karimi must ne left on or dimmed in order to illuminate the common areas.</li>
<li>The light in Karimi must ne left on or dimmed in order to illuminate the common areas.</li>
</ul> </Paper>
</Grid>
</Grid>
</TabPanel>
<TabPanel value={value} index={1} >
Daily Tasks
<TableContainer component={Paper}>
<div className={classes2.root}>
<AppBar position="static" color="default">
<Tabs
value={value}
onChange={handleChange}
indicatorColor="primary"
textColor="primary"
variant="scrollable"
scrollButtons="auto"
aria-label="scrollable auto tabs example"
>
<Tab label="Monday" {...a11yProps2(5)} />
<Tab label="Tuesday" {...a11yProps2(6)} />
<Tab label="Wednesday" {...a11yProps2(7)} />
<Tab label="Thursday" {...a11yProps2(8)} />
<Tab label="Friday" {...a11yProps2(9)} />
<Tab label="Saturday" {...a11yProps2(10)} />
<Tab label="Sunday" {...a11yProps2(11)} />
</Tabs>
</AppBar>
<TabPanel2 value={value} index={0}>
Item One
</TabPanel2>
<TabPanel2 value={value} index={1}>
Test2
</TabPanel2>
<TabPanel2 value={value} index={3}>
Item Three
</TabPanel2>
<TabPanel2 value={value} index={4}>
Item Four
</TabPanel2>
<TabPanel2 value={value} index={5}>
Item Five
</TabPanel2>
<TabPanel2 value={value} index={6}>
Item Six
</TabPanel2>
<TabPanel2 value={value} index={7}>
Item Seven
</TabPanel2>
</div>
</TableContainer>
</TabPanel>
<TabPanel value={value} index={2}>
Weekly Tasks
</TabPanel>
<TabPanel value={value} index={3}>
Other
</TabPanel>
</div>
);
}