Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement custom Tab indicator color in Material-UI v1

I have MUI v1 beta 32 running on a production site, very nicely. Time to update to v1! So far, changes have been very simple. It's mostly been a matter of updating the import tags.

But I am running into an issue with my selected <Tab/> indicator. I was using the rootInheritSelected style override in order to apply the color of my choice.

How to implement it in v1?

like image 860
dauffret Avatar asked May 25 '18 16:05

dauffret


People also ask

How do I change the material color on my UI tab indicator?

1, you can do this: import Tabs from '@material-ui/core/Tabs'; import { withStyles } from '@material-ui/core/styles'; const StyledTabs = withStyles({ indicator: { backgroundColor: 'orange' } })(Tabs);

How do you show active tabs in Materialui?

You can use the state to set the initial tab select. Show activity on this post. The value of the currently selected Tab . If you don't want any selected Tab , you can set this property to false .

How to customize tabs with material UI?

In this article, we’ll look at how to customize tabs with Material UI. We can make tabs centered with the centered prop. Then the tabs will be centered. We can make tabs scrollable with the scrollButtons set to auto and variant set to scrollable . This way, the scroll buttons will be shown on mobile and hidden in the desktop.

What is appbar in material UI?

Material-UI AppBar is a useful component for positioning titles, hamburger menus, admin buttons, and more. Styling the AppBar background color, text color, positioning, font, and any other CSS property is a common need and can be tricky to figure out.

How do I change the color of the tab indicator?

If you want to change the indicator color instead, simply apply a background color in this selector. There are likely quite a few customizations you could do here to the tab indicator size, padding, margin, or anything else interesting. I used two different approaches to customizing the tabs simply to show what is possible.

How do I use the Material Design Color System?

The Material Design color system can be used to create a color theme that reflects your brand or style. The Material Design team has also built an awesome palette configuration tool: material.io/resources/color/ . This can help you create a color palette for your UI, as well as measure the accessibility level of any color combination.


1 Answers

In the end I found it was much simpler:

<Tabs
  textColor="inherit"
  fullWidth
  centered
  classes={{
    indicator: classes.indicator
  }}>
    <Tab />
    <Tab />
</Tabs>

and the styles:

const styles = theme => ({
  indicator: {
    backgroundColor: 'white',
  },
})
like image 198
dauffret Avatar answered Oct 20 '22 17:10

dauffret