我开始使用material ui tabs,我对标签的字体大小有问题,因为它们真的很小……

这是我的代码:
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } 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 Typography from '@material-ui/core/Typography';
function TabContainer(props) {
return (
<Typography component="div" style={{ padding: 8 * 3 }}>
{props.children}
</Typography>
);
}
TabContainer.propTypes = {
children: PropTypes.node.isRequired,
};
const styles = theme => ({
root: {
flexGrow: 1,
backgroundColor: theme.palette.background.paper,
},
tabRoot: {
backgroundColor: theme.palette.background.paper,
flexGrow: 1,
color: 'black',
fontWeight: 'bold'
}
});
class SimpleTabs extends React.Component {
state = {
value: 0,
};
handleChange = (event, value) => {
this.setState({ value });
};
render() {
const { classes } = this.props;
const { value } = this.state;
return (
<div className={classes.root}>
<AppBar position="static">
<Tabs className={classes.tabRoot} value={value} onChange={this.handleChange}>
<Tab label="Item One" />
<Tab label="Item Two" />
</Tabs>
</AppBar>
{value === 0 && <TabContainer>Item One</TabContainer>}
{value === 1 && <TabContainer>Item Two</TabContainer>}
{value === 2 && <TabContainer>Item Three</TabContainer>}
</div>
);
}
}
SimpleTabs.propTypes = {
classes: PropTypes.object.isRequired,
};
export default withStyles(styles)(SimpleTabs);有没有办法增加这些标签的大小?
发布于 2018-07-25 19:06:02
Material-ui页签组件标签属性类型为节点。因此,如果你想添加样式,你需要将纯文本放在div或span中,或者另一个html组件中,然后添加className。
<Tab label={<span className={classes.tabLabel}>Label</span>}/>发布于 2019-09-03 19:07:04
1.您可以设置选项卡的样式,并使用自己的包装组件,例如TabBigger
import React from 'react';
import { withStyles } 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 Typography from '@material-ui/core/Typography';
const styles = theme => ({
root: { backgroundColor: '#0af' },
tabRoot: { backgroundColor: '#0a6' },
label: {
backgroundColor: '#aa0',
fontSize: '22px'
},
});
function TabContainer(props) {
return (
<Typography component="div" style={{ padding: 8 * 3 }}>
{props.children}
</Typography>
);
}
const TabBigger = withStyles(styles)(( props )=>{
return (
<Tab className={props.classes.label} {...props}/>
);
});
class SimpleTabs extends React.Component {
state = {
value: 0,
};
handleChange = (event, value) => {
this.setState({ value });
};
render() {
const { classes } = this.props;
const { value } = this.state;
return (
<div className={classes.root}>
<AppBar position="static">
<Tabs className={classes.tabRoot} value={value} onChange={this.handleChange}>
<TabBigger label="Item One" />
<TabBigger label="Item Two" />
</Tabs>
</AppBar>
{value === 0 && <TabContainer>Item One</TabContainer>}
{value === 1 && <TabContainer>Item Two</TabContainer>}
{value === 2 && <TabContainer>Item Three</TabContainer>}
</div>
);
}
}
export default withStyles(styles)(SimpleTabs);2.或者,您可能希望使用MUI- labelContainer来设置选项卡标签的样式(而不是整个规则组件)
<Tab classes={{ root: { props.classes.tab }, labelContainer: props.classes.label }} />https://stackoverflow.com/questions/50965941
复制相似问题