Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change tabs width in material UI

I am using material UI tabs v0.20.0 for display content in tabular format. Tabs are taking full width. I have attached screenshot of expected and current output .

Expected output enter image description here

Current Output enter image description here

Please let me know a solution for the same.

like image 816
Nitin Shinde Avatar asked Jan 29 '18 11:01

Nitin Shinde


People also ask

How do I customize my react tabs?

You can customize the Tab style by overriding its header and active tab CSS classes. Define HTML string for adding animation and customizing the Tab header and pass it to text property. Now you can override the style using custom CSS classes added to the Tab elements.


2 Answers

If you want tabs of fixed width, you need to override the root css class passed to the Tab component, where you have to override both the minWidth and width attributes.

Example:

const Component = ({ classes }) => (
    <Tabs value={0}>
        <Tab classes={{ root: classes.tab }} label="One" />
        <Tab classes={{ root: classes.tab }} label="Two" />
    </Tabs>
);


// this is injected as classes prop into the wrapping component
const styles = {
    tab: {
        minWidth: 200, // a number of your choice
        width: 200, // a number of your choice
    }
};
export default withStyles(styles)(Component);
like image 96
Honza Kalfus Avatar answered Oct 06 '22 01:10

Honza Kalfus


The Tabs component does accept a variant prop. One of the following string values are accepted:

  • fullWidth -> which is OPs current result
  • standard -> which is the default
  • scrollable -> adding scrolling functionality via buttons if not all tab items are visible

By now, the OPs expected result should be the default prop (standard).

Official Docs:

  • Tabs Guide: https://material-ui.com/components/tabs/
  • Tabs API: https://material-ui.com/api/tabs/
like image 34
Dusty48 Avatar answered Oct 06 '22 01:10

Dusty48