Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material UI Tab label font-size is really small

I started to use material ui tabs and I'm having issues with the font size of the Tab labels because they are really small...

enter image description here

This is my code:

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);

Is there any way to increase the size of those labels?

like image 460
Valip Avatar asked Jun 21 '18 10:06

Valip


2 Answers

Material-ui Tab component label prop type is node. So if you want to add styles you need to put plain text inside div or span, o another html component and add className.

<Tab label={<span className={classes.tabLabel}>Label</span>}/>
like image 157
Irmantas Ramanauskas Avatar answered Oct 23 '22 10:10

Irmantas Ramanauskas


1. You can set the style of the tab, and use an own wrapper component, e.g. like 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. Alternatively, you might want to set the style of the tab-label (instead of the whole Tab component) with the MUI-rule labelContainer:

<Tab classes={{ root: { props.classes.tab }, labelContainer: props.classes.label }} />
like image 2
kca Avatar answered Oct 23 '22 08:10

kca