Issues with customizing material-UI styling are persisting

Recently delving into the world of material UI, I have encountered an issue while trying to customize the CSS of a material UI tabs component.

<Tab
    key={`${tab}_${index}`}
    classes={{
    flexcontainer: css.tabFlexContainer
    }}
    disableRipple
    label={tab.label}
    value={tab.value}
    icon={
    tab.icon ? <Icons className={css.tabIcons} iconname={tab.icon} /> : null
    }
/>

My goal is to modify the flexContainer class using the following CSS:

. tabFlexContainer {
   width : 100%
  justify -content :space-between
}

However, when implementing this, I encounter a compilation error that reads:

TS2769: No overload matches this call.

If anyone has insights on how to resolve this issue, I would greatly appreciate the assistance.

Answer №1

Firstly, when inspecting the DOM structure

<div class="MuiTabs-root Tabs" aria-label="tabs example">
  <div class="MuiTabs-scroller MuiTabs-fixed" style="overflow: hidden;">
    <div class="MuiTabs-flexContainer" role="tablist">
    </div>
  </div>
</div>;

You will notice that the required className is MuiTabs-flexContainer (not tabFlexContainer)

For instance, in Tabs, all classNames can be found in the MUI Tabs CSS API


Various solutions are available to fully override, besides the typical withStyles and makeStyles:

1.Answer from Material-UI

1.1 Utilize the internal MUI style Higher-Order Component withStyles for complete component overriding.

Using the concept of nesting selector

import { Tabs, Tab, withStyles } from "@material-ui/core";

const StyledTabs = withStyles({
  root: {
    background: "light-blue",
    ...
    boxShadow: "0 3px 5px 2px rgba(255, 105, 135, .3)",
    "& div.MuiTabs-scroller": {
      "& .MuiTabs-flexContainer": {
        background: "linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)"
      }
    }
  }
})(Tabs);

https://i.sstatic.net/8f1UA.png


1.2 Apply normal createStyles or makeStyles style solution

Traditional component
withStyles (Higher-Order function) + createStyles

Functional aspect
useStyles (hooks) + makeStyles

Further details at:


2.Style Solution using Styled-Components

If you prefer utilizing separate CSS files to style MUI components

You can explore styled-components

styled-components allows you to write actual CSS code to style your components.

Implementation:

import styled from 'styled-components';
import { Tabs, Tab, withStyles } from "@material-ui/core";

const StyledTabs = styled.Tabs`
  font-size: 1.5em;
  ...
`;

3.Pure CSS Approach

Refer: css_selectors

import "./styles.css";
div.MuiTabs-flexContainer {
  background: linear-gradient(45deg, red 30%, #ff8e53 90%);
}

https://i.sstatic.net/ZyNET.png

https://codesandbox.io/s/gallant-keller-kwtvj?fontsize=14&hidenavigation=1&theme=dark

Answer №2

If you want to customize the appearance of your tabs using Material-UI, you can utilize the API provided to tabs. Here is an example:

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

const useStyles = makeStyles(theme => ({
    tabRoot: {
       // ...
    },
    flexContainer: {
        width : 100%
        justifyContent :"space-between"
    }

}));

export default useStyles;

When implementing in your component:

const classes = useStyles();
// ...

<Tabs
    classes={{ flexContainer: classes.flexContainer }} // override for tabs
   ...
>
    <Tab classes={{ root: classes.tabRoot}}  /> // override for tab
</Tabs>

Refer to the CSS section in these links for more details: (Tab, Tabs)

Alternatively, you can use the className prop to apply a CSS class and customize the styles as needed.

Keep in mind that this is CSS-in-JS, so the style must be defined as an object with camelCase properties, not traditional CSS.

Answer №3

Overriding Material UI styles with CSS can be challenging, but you have the option to utilize Styled-Components or the makeStyle Hook.

Answer №4

To create the space-between effect in your layout, simply include variant="fullWidth"

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

Why does my console refuse to log the input entered for the search?

Looking to become proficient in web development, I am attempting to record HTML search queries in the console after storing them in a variable. However, when I try running the search procedure, nothing seems to be displaying in my browser's inspect co ...

Issues encountered when incorporating personalized CSS into a Vuetify element

Working with the Vuetify selector input component, v-select, and wanting to customize its style led me to inspecting it in Chrome and copying down the necessary classes. For instance, to change the font size of the active value, I utilized: .v-select__sel ...

Is utilizing Eval on a div within a DataList ItemTemplate feasible for MouseOver event handling?

Apologies for the complicated title. Here is the structure of my DataList: <asp:DataList ID="DataListFloor" runat="server" RepeatColumns="5" > <ItemTemplate> <div style='width:199px;height:166px;background-color: <%# Ev ...

What is causing the delay in starting to play an audio track when it is clicked on?

I am facing an issue with my application and have created a minimum code example on StackBlitz to demonstrate the problem. The problematic code is also provided below. My goal is to have the Audio component play a track immediately when the user clicks on ...

Implementing a document click event to reset timeouts using JQuery

I'm having trouble resetting a timeout timer every time there is a click interaction with the document. The clearTimeout function doesn't seem to be working as expected. Here is the jQuery code snippet: $(document).click(function(e){ $("#vidB ...

Labeling src library files with namespaces

I have developed a ReactJS website that interacts with a library called analyzejs which was created in another programming language. While I am able to call functions from this library, I do not have much flexibility to modify its contents. Up until now, ...

Using jQuery to iterate through rendered HTML with the ForEach function

I am utilizing JS/jQuery code to extract the cell value of an ASP DetailsView control (rendered HTML), validate it against a condition, and hide a specific div based on the result. Specifically, the code is examining whether the cell value is formatted lik ...

Issue with AJAX POST request: PHP failing to establish session

I would like to pass the element's id to PHP and create a session for it. This snippet is from a PHP file: <?php $sql = "SELECT id FROM products"; $result = mysqli_query($con,$sql); while($row = mysqli_fetch_array($result)) { ?> <tr cl ...

Utilize Javascript or Jquery to intercept and handle both GET and POST requests

Is there a method to effectively intercept and capture both GET and POST requests as they are sent from the browser to the server? In my web application, full page refreshes occur after each request is submitted, however, some pages experience delays in r ...

Having trouble configuring a basic express server to host a static JavaScript file

Struggling to set up a basic Express server with accompanying HTML and JS files. Despite multiple attempts, I can't get the JS file to properly load. index.js: const express = require("express"); const app = express(); const path = require ...

"The issue of the search form CSS class loading twice and causing placement issues following the completion of the AJAX

I implemented a search form that fetches data from the server and displays it in a div, which is working smoothly. However, when I added an ajaxComplete function to add a class for animating the results, it resulted in unexpected behavior. Upon entering t ...

Combining Vueify with Elixir and Hotloading led to an unexpected error: Uncaught TypeError - property 'indexOf' is undefined

I have successfully configured Elixir to utilize Vueify with a hot reload plugin. The compilation process runs smoothly, but I encounter a console error in my compiled file and the Vue component does not seem to transform into HTML; it still displays the & ...

Blender Mesh Not Visible in Three.js

After creating a mesh in Blender, I attempted to use it in three.js. Although the file is being loaded according to the event log, all I see is a black screen. How can I ensure that the mesh actually appears on the screen? import * as THREE from 'thre ...

Align both text and images in the middle using HTML/CSS

I attempted to align an image next to text and center everything, but I'm facing some challenges. The arrow indicates where I would prefer the image to be placed. HTML <!DOCTYPE html> <head> <title>Simple Page</title> ...

Verify if there is a value in at least one of the multiple input fields

I have 4 input fields and I need to check if at least one of them has a value. If none of them are filled out, I want the function to stop. Below is the current code snippet I'm using but it's not working as expected because it doesn't ente ...

Prevent the border from shrinking upon being clicked

I'm currently working on customizing an accordion using jQuery for the animation effects. However, I am facing an issue where clicking on the accordion header causes the border around the plus sign to shrink in size as well. My goal is to only have th ...

Accessing PHP variables within a React componentTo access external

How can I pass the id selected in a menu from a react component to a PHP file, after already knowing how to send data from PHP to the react component? $.ajax({url: '/file.php', type: 'POST', dataType: 'json', ...

Newbie Question: What is the process to upload a website that consists of only HTML files to a web hosting provider

I'm embarking on creating a basic four-page website using HTML, CSS, and images. It's my maiden voyage into web design. When I finish developing the HTML files, what steps should I take to upload them and launch the website? ...

Is it possible to transform the Bootstrap5 sidebar, currently positioned above the block content, into a sticky element on

After creating a Django blog using bootstrap5 and following guidance from the python crash-course book, I encountered an issue with my sidebar placement. Despite trying various methods, I struggled to "override" my blocks in order to keep my sidebar fixed ...

Is there a way to eliminate the space between the gray background and the right edge of the browser window?

body{ font-family:'Montserrat'; } .content{ background-color:#d9d9d9; } p.dates{ display:inline-block; font-weight:800; margin-right:20px; width:120px; text-align:center; margin-top:0; margin-bott ...