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 custom color support for indicatorColor and textColor props #11085

Closed
zachrdz opened this issue Apr 20, 2018 · 26 comments
Closed

Tabs custom color support for indicatorColor and textColor props #11085

zachrdz opened this issue Apr 20, 2018 · 26 comments
Labels
component: tabs This is the name of the generic UI component, not the React module! good first issue Great for first contributions. Enable to learn the contribution process. new feature New feature or request

Comments

@zachrdz
Copy link
Contributor

zachrdz commented Apr 20, 2018

Tabs support for a custom indicatorColor value of a hexCode or RGB color seems to have been removed since sometime after version v1.0.0-beta.38. Now it only supports primary or secondary as prop values.

  • [x ] I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

When using the Tabs component and passing in an indicatorColor or textColor props value of a hexCode such as "#7C4DFF" or rgb string like "rgb(124, 77, 255)", the tabs indicator and text color should use that color given.

Current Behavior

The Tabs component indicatorColor and textColor props only support an enum of primary and secondary as their values.

Steps to Reproduce (for bugs)

Context

I have created an application that revolves around different teams and each team has their own team colors. I'm using this Tabs component to switch between displaying information about each team and I loved having the ability to have each tab colored differently depending on the team shown with the older versions. Being limited to two colors throughout the application makes sense for other components, but I feel like keeping this Tabs component customizable would be more favorable for its use cases.

Your Environment

Tech Version
Material-UI v1.0.0-beta.42
React ^16.3.1
browser Chrome
etc
@oliviertassinari oliviertassinari added the support: question Community support but can be turned into an improvement label Apr 20, 2018
@oliviertassinari
Copy link
Member

Tabs support for a custom indicatorColor value of a hexCode or RGB color seems to have been removed since sometime after version v1.0.0-beta.38. Now it only supports primary or secondary as prop values.

@zachrdz You are right. It was removed in v1.0.0-beta.42: #10999

@oliviertassinari
Copy link
Member

oliviertassinari commented Apr 20, 2018

I have created an application that revolves around different teams and each team has their own team colors.

It sounds like you need dynamic styles. We would accept a pull-request for adding a TabIndicatorProps property if that help.

@oliviertassinari oliviertassinari added new feature New feature or request good first issue Great for first contributions. Enable to learn the contribution process. component: tabs This is the name of the generic UI component, not the React module! and removed support: question Community support but can be turned into an improvement labels Apr 20, 2018
@zachrdz
Copy link
Contributor Author

zachrdz commented Apr 20, 2018

Great! Thank you for the response and clarification. I will work on a pull request for this enhancement.

@adeelibr
Copy link
Contributor

Is anyone working on this actively? If not, I would love to get my hands dirty.
I have been meaning to start contributing & would love to work on this one and figure stuff out.

@oliviertassinari
Copy link
Member

@adeelibr You are free to go 🏎 :)

@adeelibr
Copy link
Contributor

adeelibr commented May 6, 2018

@oliviertassinari I tested it with primary, secondary, hex codes, rgba color code. The indicator color is now changing. Can you kindly review my PR #11254

@tyrsensei
Copy link

Hello,

Sorry to refresh a closed issue, but I don't see how you can change de TabIndicator color with the new TabIndicatorProps property.

It appears that defining the style overrides the one generated by the Tabs component (indicatorStyle that is, changing its width).

Could someone please enlighten me ?

Thanks in advance.

@oliviertassinari
Copy link
Member

It appears that defining the style overrides the one generated by the Tabs component

@tyrsensei You are right. We can do a second iteration on the issue to correctly merge the style.

@adeelibr
Copy link
Contributor

Can I work on this second iteration again? @oliviertassinari

@oliviertassinari
Copy link
Member

@adeelibr Sorry, I should have kept your merge logic 👍.

@adeelibr
Copy link
Contributor

No worries, I'll add that change again, & update it with a PR.

@jpung
Copy link
Contributor

jpung commented May 16, 2018

@oliviertassinari I'm not sure if it was the intention but there no longer is a MuiTabIndicator style that can be overridden via createMuiTheme. I've noticed this on top of a few other css classes that no longer start with Mui (e.g MuiStepPositionIcon is now StepPositionIcon).

I understand the reasoning behind the change(allowing custom css change from the component end), however is it possible to still allow global overriding? or at least access to the style for changes. As of now any changes made on the themes overrides will not work if they are on these new class names.

@oliviertassinari
Copy link
Member

oliviertassinari commented May 19, 2018

I'm not sure if it was the intention but there no longer is a MuiTabIndicator style that can be overridden via createMuiTheme.

@josephpung Yes, it's intentional.

I've noticed this on top of a few other css classes that no longer start with Mui (e.g MuiStepPositionIcon is now StepPositionIcon).

It only works in development mode. I have never seen someone trying to use it. At some point, we might want to prevent this in the first place to avoid people realizing it doesn't work once in production.

however is it possible to still allow global overriding?

You can still override the style. Use theme.overrides.MuiTabs.indicator.

@adeelibr
Copy link
Contributor

I have made a PR can you kindly have a look at it #11494 @oliviertassinari

@ChaoTzuJung
Copy link

ChaoTzuJung commented Jun 5, 2018

Excuse me, I add TabIndicatorProps property in Tabs and give height and color , but it not work !?

And Material UI document said

Tabs component is a public module while TabIndicator is private.

https://material-ui.com/guides/minimizing-bundle-size/#option-1

So , Can I change Props indicatorColor to other style ?

@oliviertassinari
Copy link
Member

oliviertassinari commented Jun 6, 2018

How can I change the indicator color?

@ChaoTzuJung You have two options. Either you can use the CSS API with the classes.indicator customization point or you can use the inline-style API with the TabIndicatorProps property (style.backgroundColor).

@mui mui deleted a comment from adeelibr Jun 6, 2018
@mui mui deleted a comment from adeelibr Jun 6, 2018
@mui mui deleted a comment from adeelibr Jun 6, 2018
@mui mui deleted a comment from adeelibr Jun 6, 2018
@mui mui deleted a comment from mbrookes Jun 6, 2018
@mui mui deleted a comment from adeelibr Jun 6, 2018
@mui mui deleted a comment from adeelibr Jun 6, 2018
@mui mui deleted a comment from adeelibr Jun 6, 2018
@yaminyaylo
Copy link

I think it will be better to have TabIndicator element (with it's CSS Api) in a Component Api. But the best would be overriding in theme.

@tonymckendry
Copy link

@oliviertassinari are the docs wrong about setting the indicatorColor prop to "primary" or "secondary" now? Doesn't seem to be working for me that way, and based on your previous comment looks like this is done differently now? Just want to be sure, and I'll put in a PR for you!

@tonymckendry
Copy link

Scratch that - I got it working now. My mistake!

@Jonathanx5
Copy link

Jonathanx5 commented Nov 13, 2018

Could Help ....
For this work perfectly

<Tabs
  value={value}
  onChange={this.handleChange}
  TabIndicatorProps={{
    style: {
      backgroundColor: "#D97D54"
    }
  }}
>
...
</Tabs>

or you can target the .MuiTabs-indicator class name.

@tavishiChat
Copy link

above thing worked for me
Thanks

@japrogramer
Copy link

the above only changes the bottom indicator, how do i change the background color of the entire tab?

image

@F1LT3R
Copy link

F1LT3R commented Jun 10, 2020

What about a custom textColor?

@zachrdz
Copy link
Contributor Author

zachrdz commented Jun 10, 2020

What about a custom textColor?

This can be changed using the CSS API to override the existing css classes that are being used by the component. Here is an example where we provide a custom indicator color, background color and text color by modifying the root and indicator classes that are used by the Tabs component. We create our own classes and hand them over to map to the existing classes.

const useStyles = makeStyles(theme => ({
  customTabRoot: {
      color: "red",
      backgroundColor: "green"
  },
  customTabIndicator: {
      backgroundColor: "orange"
  }
}));

...
...

const classes = useStyles();

...

<Tabs
     value={value}
     onChange={handleChange}
     aria-label="simple tabs example"
     classes={{
         root: classes.customTabRoot,
         indicator: classes.customTabIndicator
     }}
>
     <Tab label="Item One" {...a11yProps(0)} />
     <Tab label="Item Two" {...a11yProps(1)} />
     <Tab label="Item Three" {...a11yProps(2)} />
</Tabs>

Here is a CodeSandbox with the above snippet working.

@adisher
Copy link

adisher commented Jul 23, 2020

I was searching for the solution and found the following on Stackoverflow:

<Tabs
  TabIndicatorProps={{
    style: {
      height:"10px",
    }
  }}
  onChange={handleChange}
  value={value}
>
  <Tab label="Item One" />
  <Tab label="Item Two" />
  <Tab label="Item Three" />
</Tabs>

I wanted to read more so came here from another GitHub duplicate issue. Love this community support!

@OferLahav2
Copy link

What about a custom textColor?

This can be changed using the CSS API to override the existing css classes that are being used by the component. Here is an example where we provide a custom indicator color, background color and text color by modifying the root and indicator classes that are used by the Tabs component. We create our own classes and hand them over to map to the existing classes.

const useStyles = makeStyles(theme => ({
  customTabRoot: {
      color: "red",
      backgroundColor: "green"
  },
  customTabIndicator: {
      backgroundColor: "orange"
  }
}));

...
...

const classes = useStyles();

...

<Tabs
     value={value}
     onChange={handleChange}
     aria-label="simple tabs example"
     classes={{
         root: classes.customTabRoot,
         indicator: classes.customTabIndicator
     }}
>
     <Tab label="Item One" {...a11yProps(0)} />
     <Tab label="Item Two" {...a11yProps(1)} />
     <Tab label="Item Three" {...a11yProps(2)} />
</Tabs>

Here is a CodeSandbox with the above snippet working.

this is a better solution then the one provided in the official docs. Maybe the docs should be updated?

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! good first issue Great for first contributions. Enable to learn the contribution process. new feature New feature or request
Projects
None yet
Development

No branches or pull requests