答案 0 :(得分:7)
Material-ui Tab组件标签的prop类型为node。因此,如果要添加样式,则需要在div或span内放入纯文本,或者添加另一个html组件并添加className。
<Tab label={<span className={classes.tabLabel}>Label</span>}/>
答案 1 :(得分:0)
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规则设置标签标签的样式(而不是整个Tab
组件) labelContainer
:
<Tab classes={{ root: { props.classes.tab }, labelContainer: props.classes.label }} />