Reactjs 水平滚动在材质ui选项卡中不起作用?
我正在从头开始构建react js应用程序。有时我会使用动态选项卡,其中选项卡的长度可能无法定义。我已经从material ui中找到了可滚动选项卡的代码。但是,除了tab的水平滚动超过特定长度外,其他一切都正常工作Reactjs 水平滚动在材质ui选项卡中不起作用?,reactjs,material-ui,Reactjs,Material Ui,我正在从头开始构建react js应用程序。有时我会使用动态选项卡,其中选项卡的长度可能无法定义。我已经从material ui中找到了可滚动选项卡的代码。但是,除了tab的水平滚动超过特定长度外,其他一切都正常工作 import React from 'react'; import PropTypes from 'prop-types'; import { makeStyles } from '@material-ui/core/styles'; import AppBar from '@ma
import React from 'react';
import PropTypes from 'prop-types';
import { makeStyles } from '@material-ui/core/styles';
import AppBar from '@material-ui/core/AppBar';
import Tabs from '@material-ui/core/Tabs';
import Tab from '@material-ui/core/Tab';
import PhoneIcon from '@material-ui/icons/Phone';
import FavoriteIcon from '@material-ui/icons/Favorite';
import PersonPinIcon from '@material-ui/icons/PersonPin';
import HelpIcon from '@material-ui/icons/Help';
import ShoppingBasket from '@material-ui/icons/ShoppingBasket';
import ThumbDown from '@material-ui/icons/ThumbDown';
import ThumbUp from '@material-ui/icons/ThumbUp';
import Typography from '@material-ui/core/Typography';
import Box from '@material-ui/core/Box';
function TabPanel(props) {
const { children, value, index, ...other } = props;
return (
<div
role="tabpanel"
hidden={value !== index}
id={`scrollable-force-tabpanel-${index}`}
aria-labelledby={`scrollable-force-tab-${index}`}
{...other}
>
{value === index && (
<Box p={3}>
<Typography>{children}</Typography>
</Box>
)}
</div>
);
}
TabPanel.propTypes = {
children: PropTypes.node,
index: PropTypes.any.isRequired,
value: PropTypes.any.isRequired,
};
function a11yProps(index) {
return {
id: `scrollable-force-tab-${index}`,
'aria-controls': `scrollable-force-tabpanel-${index}`,
};
}
const useStyles = makeStyles((theme) => ({
root: {
flexGrow: 1,
width: '100%',
backgroundColor: theme.palette.background.paper,
},
}));
export default function TabsButton() {
const classes = useStyles();
const [value, setValue] = React.useState(0);
const handleChange = (event, newValue) => {
setValue(newValue);
};
return (
<div className={classes.root}>
<AppBar position="static" color="default">
<Tabs
value={value}
onChange={handleChange}
variant="scrollable"
scrollButtons="on"
indicatorColor="primary"
textColor="primary"
aria-label="scrollable force tabs example"
>
<Tab label="Item One" icon={<PhoneIcon />} {...a11yProps(0)} />
<Tab label="Item Two" icon={<FavoriteIcon />} {...a11yProps(1)} />
<Tab label="Item Three" icon={<PersonPinIcon />} {...a11yProps(2)} />
<Tab label="Item Four" icon={<HelpIcon />} {...a11yProps(3)} />
<Tab label="Item Five" icon={<ShoppingBasket />} {...a11yProps(4)} />
<Tab label="Item Six" icon={<ThumbDown />} {...a11yProps(5)} />
<Tab label="Item Seven" icon={<ThumbUp />} {...a11yProps(6)} />
<Tab label="Item Five" icon={<ShoppingBasket />} {...a11yProps(4)} />
<Tab label="Item Six" icon={<ThumbDown />} {...a11yProps(5)} />
<Tab label="Item Seven" icon={<ThumbUp />} {...a11yProps(6)} />
</Tabs>
</AppBar>
<TabPanel value={value} index={0}>
Item One
</TabPanel>
<TabPanel value={value} index={1}>
Item Two
</TabPanel>
<TabPanel value={value} index={2}>
Item Three
</TabPanel>
<TabPanel value={value} index={3}>
Item Four
</TabPanel>
<TabPanel value={value} index={4}>
Item Five
</TabPanel>
<TabPanel value={value} index={5}>
Item Six
</TabPanel>
<TabPanel value={value} index={6}>
Item Seven
</TabPanel>
<TabPanel value={value} index={4}>
Item Five
</TabPanel>
<TabPanel value={value} index={5}>
Item Six
</TabPanel>
<TabPanel value={value} index={6}>
Item Seven
</TabPanel>
</div>
);
}
从“React”导入React;
从“道具类型”导入道具类型;
从'@material ui/core/styles'导入{makeStyles};
从“@material ui/core/AppBar”导入AppBar;
从“@material ui/core/Tabs”导入选项卡;
从“@material ui/core/Tab”导入选项卡;
从“@material ui/icons/Phone”导入PhoneIcon;
从“@material ui/icons/Favorite”导入收藏夹图标;
从“@material ui/icons/PersonPin”导入PersonPinIcon;
从“@material ui/icons/Help”导入帮助图标;
从“@material ui/icons/ShoppingBasket”导入ShoppingBasket;
从“@material ui/icons/ThumbDown”导入缩略图;
从“@material ui/icons/ThumbUp”导入缩略图;
从“@material ui/core/Typography”导入排版;
从“@material ui/core/Box”导入框;
功能选项卡面板(道具){
const{children,value,index,…other}=props;
返回(
{value===索引&&(
{儿童}
)}
);
}
TabPanel.propTypes={
子项:PropTypes.node,
索引:PropTypes.any.isRequired,
值:PropTypes.any.isRequired,
};
功能a11yProps(索引){
返回{
id:`scrollable force tab-${index}`,
“aria控件”:“可滚动的强制选项卡面板-${index}”,
};
}
const useStyles=makeStyles((主题)=>({
根目录:{
flexGrow:1,
宽度:“100%”,
背景色:theme.palete.background.paper,
},
}));
导出默认函数选项卡按钮(){
const classes=useStyles();
const[value,setValue]=React.useState(0);
常量handleChange=(事件,newValue)=>{
设置值(新值);
};
返回(
项目一
项目二
项目三
项目四
项目五
项目六
项目七
项目五
项目六
项目七
);
}
感谢您的帮助您面临的问题是什么?我运行了这段代码,但没有引起我的注意。请创建一个工作示例来演示这个问题。您可以使用。您可能有多少个选项卡?我用200试过了,但效果很好,标签的滚动条没有显示出来……你面临的问题是什么?我运行了这段代码,但没有引起我的注意。请创建一个工作示例来演示这个问题。您可以使用。您可能有多少个选项卡?我尝试了200,它是工作良好的标签滚动不显示。。。