What is the best way to customize the label of Material UI's Tab component?

Is there a way to customize the text color inside the Tab component while still allowing it to change color when selected as an active Tab?

For example:

<Tabs centered onChange={handleChange} value={value} textColor={'secondary'} indicatorColor={'secondary'}>
    <Tab label={'Hello There'} style={{color: '#fff'}}/>
    <Tab label={'Hello There'} style={{color: '#fff'}}/>
    <Tab label={'Hello There'} style={{color: '#fff'}}/>
</Tabs>

The code above changes the text color but does not override the color when the Tab is active.

In addition, I am using styled-components for convenience.

Answer №1

To create a custom class for the label, utilize the makeStyles export from material-ui.

import { makeStyles } from "@material-ui/core";

const useStyles = makeStyles({
  customLabelColor: {
    color: "#fff"
  }
});

export default function CustomApp() {
  const classes = useStyles();
  return (
    ...
    <Tab
      label={"Hello There"}
      classes={{
        textColorSecondary: classes.customLabelColor
      }}
    />
    ...
  );
}

Check out the CodeSandBox example link here: https://codesandbox.io/s/quirky-kowalevski-xzf7g?file=/src/App.js


For more ways to override the CSS for the Tab component, refer to this link.

In the same documentation, pay attention to the textColorSecondary rule name which is relevant if you are using textColor="secondary" on the parent component Tabs.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

My goal is to create a stylish form using bootstrap and CSS3

I am aiming to replicate the layout of this particular page: https://i.sstatic.net/HxOhC.png Struggling to utilize css3 for designing, how can I achieve a form similar to this? Facing difficulty in creating the outer red border and inserting spacing betw ...

What is the best method for testing an npm package that has been delivered as a .tgz file in a React

I have a npm package that is in .tgz file format included in my react application. When I try to test a react component using jest that imports this package, I encounter the following error. Do I need to configure something in jest for testing? Jest e ...

What is the best way to transfer a UserID from State to a GET URL?

I have my userInfo saved in a state variable const [users, setUsers] = useState([]) I need help passing the userId into the axios URL to fetch posts of a specific user. Here's what I have tried. I know it's not correct, so please assist me. Das ...

My website's logo is not appearing on the navigation bar in the HTML code

Hi there! I recently tried adding a logo to my navigation bar in an HTML file, but for some reason, the logo doesn't appear when I run the file. I'm currently learning web development through a course on Coursera, and I am quite new to programmin ...

Tips on adjusting the size of a font icon using an inline element prior to the font being fully loaded

I'm facing an issue with embedding an icon font within text so that it wraps properly. Currently, the only way I can achieve this is by using &nbsp; between the text and the icon (i tag with font awesome). However, this causes a problem as the ico ...

Distinguishing the switch function from the React switch operator (jsx, tsx)

We are in the process of converting our portfolio from JavaScript to TypeScript, utilizing NextJS as the frontend framework and Strapi as the backend. To enable dynamic content, we have implemented a dynamiczone field within the post model that is accesse ...

Can anyone explain why my inner div's display is set to block and it is being pushed down when its parent div has

Below is a sample of my HTML+CSS code: <div> <div class="first">text</div> <div>more text</div> </div> div { display: inline; } .first { display: block; } What's interesting is that when the first ...

How can we combine Angular Gradients and CSS Webkit Gradients for a modern design

Can a gradient be created that resembles the color picker style shown here? The outer part showing full saturated, 50% brightness values and transitioning towards the inside to 100% brightness. https://i.sstatic.net/ohuF4.jpg ...

What is the best way to remove an input field in KeyboardDatePicker from Material UI?

Currently experimenting with the KeyboardDatePicker component. It works fine in one form where an input field is needed, but in another scenario, I only require an icon to open and select the date. <KeyboardDatePicker disableToolbar ...

There seems to be an issue with the parsing of the code - an unexpected token was encountered when a semicolon was expected. Can

What seems to be the issue? I encountered an error while attempting to compile the code: Parsing error: Unexpected token, expected ";" Here is the snippet of the code: <https://pastebin.com/GNbdiG9P> import React, { useState, useEffect } from &a ...

I recently started learning Next.js and I'm interested in organizing my website with multiple page folders but still using a single dynamic route labeled as [id]

my-nextjs-app/ |-- .next/ |-- node_modules/ |-- public/ |-- src/ | |-- components/ | |-- men/ | | |-- [id]/ | | |-- page.tsx # Specific ID static page for Men's category | | |-- page.tsx # General stat ...

Pass theme-specific properties to components using a Theme provider from an external library

I am in the process of structuring my react project by linking my custom components from @material-ui as an external dependency. Using rollup, I successfully built and published my external dependency on npm. I am able to import it into my project, and the ...

Opacity: When the value is set to 0, the element remains invisible even when hovered over

I'm encountering an issue with configuring an element to have absolute positioning and a width and height of 100% while setting its opacity to 1.0. To summarize, here is the HTML code I am working with: <ul class="properties"> <li style ...

CSS: using syntax to target element by its unique identifier

Check out this guide: I followed the instructions and used an external stylesheet. I added #menu before each CSS item, for example: #menu ul{ font-family: Arial, Verdana; font-size: 14px; margin: 0; padding: 0; list-style: none;} or: #menu ul li{ displ ...

The React Component is caught in a loop of continuous re-rendering and reloading

Just starting out with React and tackling my first project. Running into a bit of trouble here, so I'm sharing my code for some insight. When users input their search term and hit 'search,' they are redirected from another page to this one. ...

Receiving error messages about missing images in my React project

I am new to programming and I have encountered an issue while running my React project. When I use the command npm start, I noticed that some image resources are not being packaged properly, resulting in certain images disappearing when the website is run ...

What is the best way to choose two <li> elements with multiple classes in my WordPress navigation menu?

I am looking for a JavaScript function that will add the class "current_highlight" when an element with the class "activo2" also has the class "active". Here is my HTML code: <div class="navbar-header"> <button type="button " class="navbar-to ...

Issue with function not returning a list of radio buttons in ReactJS using ReactBootstrap

I'm currently developing a dashboard that retrieves data from Acuity Scheduling. I'm creating a form and utilizing a function to generate a list of radio buttons - the following array showcases this process. Due to the time required to fetch data ...

How can we redirect using an OnClick event handler in React.js?

I've been doing a lot of reading and trying to understand how to redirect using withRouter in React. However, I came across some information stating that when onClick occurs, the page should be redirected to a specific link. Additionally, I learned th ...

Issue with bouncing dropdown menu

I am in the process of enhancing a Wordpress website by implementing a jQuery menu with sub-menus. Below is the jQuery code snippet: $(document).ready(function(){ $('.menu > li').hover(function(){ var position = $(this).position(); ...