Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tabs] Add support for prefix icons #11653

Closed
2 tasks done
ghost opened this issue May 31, 2018 · 20 comments · Fixed by #28764
Closed
2 tasks done

[Tabs] Add support for prefix icons #11653

ghost opened this issue May 31, 2018 · 20 comments · Fixed by #28764
Labels
component: tabs This is the name of the generic UI component, not the React module! new feature New feature or request priority: important This change can make a difference

Comments

@ghost
Copy link

ghost commented May 31, 2018

In tabs component the icon only display on the top. I prefer the icon on the left like the image show below.

  • This is a v1.x issue (v0.x is no longer maintained).
  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

screenshot from 2018-05-31 20-05-37

Current Behavior

screenshot from 2018-05-31 20-05-00

Your Environment

Tech Version
Material-UI v1.1.0
React 16.4.0
browser Firefox, Google Chrome
@jeffvandyke
Copy link

I haven't tried this, but could you use one of those icons as just part of the text for a normal tab to get that appearance?

@mbrookes mbrookes added component: tabs This is the name of the generic UI component, not the React module! new feature New feature or request labels May 31, 2018
@mbrookes
Copy link
Member

@vibolvireak For the moment we are focusing on meeting the spec given all the Material v2 changes to address. You can probably achieve this with some custom styling though. If you manage to come up with an elegant solution, by all means share it here.

Thanks for the suggestion though.

@ghost
Copy link
Author

ghost commented May 31, 2018

@mbrookes @jeffvandyke The way i achieve this is by inject a code like below

<tab label={<Icon /> Some other label} />

Apply style on <Icon /> for resize the fontSize, margin, color to fit the what you need.

screenshot from 2018-05-31 21-01-17
but that's not really a good solution because it's really hard to align the margin.

@Hocdoc
Copy link
Contributor

Hocdoc commented Mar 6, 2019

For better aligning it is possible to decrease the icon size:

<tab label={<><Icon fontSize="inherit" /> Some other label</>} />

Another solution (depending on the icon) is to use the viewBox of the SvgIcon:

<tab label={<><Icon viewBox="0 -5 24 24" /> Some other label</>} />

@ekfrl2815
Copy link

ekfrl2815 commented Aug 2, 2019

<Tab label={<><div>Some other label<Icon/></div></>}/>

@zackeilholz2
Copy link

It would be great to see a toggleable implementation of this (leading icon, top, none) as shown in Material.io: https://material.io/components/tabs/

@mbrookes
Copy link
Member

Huh, it seems MWC have implemented it, even though it still isn't part of the spec. Not sure whether to reopen this issue or not...

@joshwooding
Copy link
Member

@zackeilholz2 I've been taking a little break but I'm currently working on building a generic component we can use across the demos to replicate those showcases.

@nvdunginest
Copy link

nvdunginest commented Sep 24, 2019

// Override MuiTab in theme.js
overrides: {
  MuiTab: {
    wrapper: {
      flexDirection:'row',
    },
  },
},

Hope this help!

@raza2022
Copy link

is there any default way to achieve it, as if I override the theme js then it will effect the tab in whole application, but I wanna this in only two components?

@mbrookes
Copy link
Member

@raza2022 you can apply @nvdunginest's suggestion locally:
https://material-ui.com/customization/components/

@sanjeeviraj
Copy link

@raza2022 here is the sample local customization:

const useStyles = makeStyles({    
    wrapper: {
      flexDirection: 'row'
    }
});
//inside render at respective area
<Tabs
	value={value}
	onChange={handleChange}
	indicatorColor="secondary"
	textColor="primary"
	centered
	className={classes.wrapper}
>
	<Tab label="File Upload" />
	<Tab label="Network Upload" />                                
</Tabs>

@adybaby
Copy link

adybaby commented Jan 6, 2020

I've tried all of these suggestions and cannot for the life of me get any of them to work :( No matter what I do - embed the icon in the label, specify flexDirection: 'row' on tabs or tab or wrapper,, the icon always stays above the label.

@oliviertassinari oliviertassinari added support: question Community support but can be turned into an improvement and removed new feature New feature or request labels Jan 6, 2020
@prbagdia
Copy link

prbagdia commented Jan 8, 2020

I tried the following way and it seemed to work for me. Let me know if this helps.

<Tab label={<div><StorageIcon style={{verticalAlign: 'middle'}} /> Data </div>}  />

@adybaby
Copy link

adybaby commented Jan 8, 2020

That worked!! Thank you so much :)

@prbagdia
Copy link

prbagdia commented Jan 9, 2020

That worked!! Thank you so much :)

Great :)

@adityapatnaik
Copy link

I tried the following way and it seemed to work for me. Let me know if this helps.

<Tab label={<div><StorageIcon style={{verticalAlign: 'middle'}} />  Data</div>}  />

Thank you so much, it worked like a charm

@amad3v
Copy link

amad3v commented Sep 9, 2020

The way I mange this is by using a Button then assign it to the Tab's label

const tabButton = (
  <Button variant="text" startIcon={icon} fullWidth>
    {label}
  </Button>
);

const customTab = <Tab label={btn}></Tab>;

Screenshot

@bgkoala
Copy link

bgkoala commented Jan 24, 2021

For those still fretting with the styling, here's what I did so it would turn out formatted perfectly with 24x24px icons:

<Tab
  value={'tabValue'}  
  label={  
    <>  
      <Icon  
        style={{ verticalAlign: 'middle', marginBottom: 2, marginRight: 6 }}  
        color={selectedTab === tabValue ? 'blue' : '#555555'}  
      />  
      Tab Label  
    </>  
  }  
/>  

Where Icon is a React component that returns a hardcoded element with 'style' and 'fill' props set via the passed 'style' and 'color' props respectively. Even with 'verticalAlign' set to 'middle' the icon still sits a little too low, hence the 2 pixels of 'marginBottom'. The amount of pixels for 'marginRight' just depends on how close you want the icon to be to the text. The #555555 (dark gray) color for the icon when tab is not selected is slightly darker than the label (which is black with 54% opacity against a white background in my case) but it just seems to blend in better. Good luck folks!

@oliviertassinari oliviertassinari removed the support: question Community support but can be turned into an improvement label Jan 24, 2021
@oliviertassinari oliviertassinari added the new feature New feature or request label Jan 24, 2021
@oliviertassinari oliviertassinari changed the title There should be a way to show the icon on tab to be left of the text on the tab item [Tabs] Add support for prefix icons Jan 24, 2021
@orxanaliyev
Copy link

Here is some example, what I did.
Screen Shot 2021-02-02 at 16 53 24

<Tab label={
              <>
                <div style={{display: "flex", flexDirection: "row", alignItems: "center"}}>
                  <FavoriteIcon fontSize="inherit" /> Some title
                </div>
              </>
         }
/>

@oliviertassinari oliviertassinari added the priority: important This change can make a difference label Feb 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: tabs This is the name of the generic UI component, not the React module! new feature New feature or request priority: important This change can make a difference
Projects
None yet
Development

Successfully merging a pull request may close this issue.