Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material UI - Tab icon Styles

I'm using this tabs dynamically:

        <Tabs
          value={value}
          onChange={handleChange}
          variant="scrollable"
          scrollButtons="off"
          indicatorColor="primary"
          textColor="primary"
          aria-label="scrollable"
          classes={{
            indicator: classes.indicator,
            flexContainer: classes.flexContainer,
          }}
        >
          {routes.map((value, index) => (
            <Tab
              classes={{
                root: classes.tabRoot,
                wrapper: classes.wrapper,
                labelIcon: classes.labelIcon,
                selected: classes.selected,
              }}
              key={index}
              label={strings(value)}
              icon={getIcon(value)}
              {...a11yProps(index)}
            />
          ))}
          {<Grid container>
            <Grid item xs>
              <PrintButton
                type= "widget"
                params={queryParams}
                style={{
                  textTransform: "capitalize",
                  float: "right"
                }}
              />
            </Grid>
          </Grid>}
        </Tabs>

this is the getIcon function:

const getIcon = (value) => {
  if (value === eventType.view) return <PageviewIcon />;
  if (value === eventType.lead) return <ContactsIcon />;
  if (value === eventType.share) return <ShareIcon />;
  if (value === eventType.follow) return <GroupAddIcon />;
  if (value === eventType.media) return <PermMediaIcon />;
  if (value === eventType.print) return <FindInPageIcon />;
  return null;
};

Each tab is looking this way: enter image description here

And I'm trying to separete with some padding the icon from the label like this: enter image description here

But I wasn't able to find a way to replace this class MuiTab-labelIcon .MuiTab-wrapper which comes likes this by default: enter image description here

I wasn't having this issue before updating to Material UI v4

I tried with inline styling on the icons but causes the icon to be really small: enter image description here

<ShareIcon style={{paddingBottom: '0px', paddingRight: "10px"}}/>

I'll appreciate any help, Thanks in advance !!

like image 886
Lorenzo Zuluaga Avatar asked Jan 24 '26 17:01

Lorenzo Zuluaga


2 Answers

Wrap Text and Icon with a parent component and apply

style={{ display: 'flex', alignItems: 'center', flexDirection: 'row', justifyContent: 'center' }}
like image 64
Nabil214 Avatar answered Jan 27 '26 06:01

Nabil214


Use the iconposition prop of the Tab component.

<Tab icon={<PhoneMissedIcon />} iconPosition="start" label="start" />
like image 43
Erham Muhammed Avatar answered Jan 27 '26 06:01

Erham Muhammed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!