Certain material-ui components may not be influenced by either createTheme or ThemeProvider

In my current project, I am developing an application using react and material-ui. The default material-ui components come with a classic blue-grey google style color scheme, but I wanted to customize them with my own colors. To achieve this, I utilized the createTheme() function from mui to define my custom palette:

import { createTheme } from "@mui/material/styles";

export const theme = createTheme({
  palette: {
    primary: {
      light: "yellow",
      main: "red",
      dark: "green",
      contrastText: "#000"
    },
    secondary: {
      light: "blue",
      main: "purple",
      dark: "orange",
      contrastText: "#000"
    },
    action: {
      active: "magenta",
      hover: "cyan",
      selected: "black"
    }
  }
});
export default theme;

While this customization worked well for most components, I noticed that the icons within the BasicSpeedDial component were not affected by the hover styling. Is this the expected behavior? I am wondering if there is a way to modify the styles of these components using createTheme() instead of manually adding styles with sx props. Additionally, I am curious if it's possible to create a global theme for all future imported mui components.

For reference, here is a link to a codesandbox showcasing a minimal reproducible example: https://codesandbox.io/s/focused-hugle-w6ir90?file=/src/BasicSpeedDial.js

Answer №1

As stated in the documentation:

Customizing components with themes

By utilizing a component's key within the theme, you have the ability to personalize its styles, default props, and more.

Follow these steps to customize a component:

  1. Identify the component name, such as MuiSpeedDialAction
  2. Refer to the relevant API page, like this one
  3. Determine the rule name located in the css classes section, e.g., fab
  4. Implement the customization in the theme:
    theme.components.${componentName}.styleOverrides.${ruleName}

For additional information on customizing components, check out how to customize. There, you'll discover how to modify various variants like outlined and contained, as well as pseudo selectors including hover and active.

// theme.js
import { createTheme } from "@mui/material/styles";

export const theme = createTheme({
  palette: {
    primary: {
      light: "yellow",
      main: "red",
      dark: "green",
      contrastText: "#000"
    },
    secondary: {
      light: "blue",
      main: "purple",
      dark: "orange",
      contrastText: "#000"
    },
    action: {
      active: "magenta",
      hover: "cyan",
      selected: "black"
    }
  },
  // HERE
  components: {
    // Component name
    MuiSpeedDialAction: {
      styleOverrides: {
        // Rule name
        fab: {
          border: "5px solid red",
          "&:hover":{
            backgroundColor:"red",
            color:"red"
          }
        }
      }
    },
  }
});
export default theme;

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

Align navigation items in the center of the navigation container

I've been grappling with aligning the content of a nav-item inside a nav container in my project. I'm unable to apply a margin on the ul>li items as it doesn't adjust properly on different resolutions. I've tried using percentages, b ...

Encountering difficulties in sending the data to Firebase through the contact form

import React, { useState } from 'react' import styled from 'styled-components' import Title from '../Components/Title' import { InnerLayout, MainLayout } from '../Styles/Layout' import ...

Ensuring Proper Alignment in Bootstrap

https://i.sstatic.net/bGTXG.jpg https://i.sstatic.net/4Vh1k.jpg Having some difficulties displaying JSON data in a grid layout with React. Facing the following challenges: Uneven spacing due to less margin on the left side. Attempts to align ...

Are you looking to combine Jquery's .hover and .hoverIntent functions in your code?

Looking for help with getting two scripts to work together, I am struggling to write the code that will make them function in unison. Specifically, I have a Jquery .hoverIntent placed on the first li element of my mega menu and a Jquery .hover event to dar ...

Learn how to utilize ng2-file-upload in Angular for uploading .ply files effortlessly!

I'm currently working on uploading various files using ng2-file-upload. I've been successful in uploading different file types like png and jpg, but I'm facing an issue with the .ply file extension. Can someone guide me on how to upload a fi ...

Connecting the SpotifyAPI to the spotifyplayer for seamless music integration

I'm currently facing some difficulties with the SpotifyPlayer now that it's only available for premium users. I'm curious if there are any alternative methods to play music from Spotify without relying on react-spotify-web-playback... Here ...

Is there a way to ensure that axios.get runs synchronously?

Here is my Node.js code for scraping 1337x.to. Initially, I successfully scraped the search results and then proceeded to extract the URLs of the torrents along with their magnet links. While this process worked fine within different functions, I encounter ...

Guidelines for displaying a React component upon landing

I am a beginner in react app development and I am currently trying to add a component that loads when the app opens. However, I encountered an issue where the console displays the message Matched leaf route at location "/" does not have an elemen ...

Adjusting size of a div as you scroll - Java Script

Using the codepen provided at http://codepen.io/anon/pen/fDqdJ, I am looking to enhance the functionality by implementing a feature where, upon reaching a specific distance from the top of the page, an already animated div undergoes a change in scale while ...

Is the window frozen while Ajax processes the request?

When I make an ajax request that may take a significant amount of time to process on the server-side, I want to display a loading image during the request. However, the loading image is not showing up while the ajax request is processing. var ref = create ...

What is the best way to retrieve child elements from JSON within an Angular JS controller?

I'm having trouble understanding how to ensure the resource call completes before assigning the data.properties to $scope in my controller. My confusion lies here: The resource call returns the following response: [ { "PreAlertInventory": "5.00 ...

The file reading code in my Node.js application suddenly stopped working

I have a basic web application that I am currently developing using Node.js and Express. This is a breakdown of my package structure: https://i.stack.imgur.com/D7hJx.png The entries in my questions.json file are outlined below: [ { "question": "Wh ...

The methods $.get() and $.ajax() in jQuery are failing to retrieve data from PHP

I've been trying to use a script to display a message from a PHP file after a click event, but I've run into issues with both jQuery $.get() and $.ajax(). With $.ajax(), I get an alert with an empty message, while $.get() alerts "null". load.php ...

Ways to restart character count to zero if textarea is blank using jQuery

Can someone assist me with resetting the character count to zero when the textarea field is empty in jQuery? Currently, I have implemented code that successfully adds the character count as shown below; $(document).ready(function() { $('#content& ...

Slide containing Ionic list views

In my Ionic app, I am using ion-slide-box with 3 slides. Each slide contains an ion-list (table view) with varying numbers of items. The issue is that when scrolling through the shorter list items, it shows empty content due to the taller sibling list taki ...

Problem with keyframe animations in Internet Explorer 10

My CSS animation works flawlessly in all modern browsers, except for IE10 which is causing some trouble. It appears that IE is having difficulty properly rotating 360deg. I am still searching for a workaround that won't compromise the functionality in ...

Stop watching a stream of data when it reaches a specific value

Is there a way to automatically unsubscribe from an observable upon receiving a specific value? For example: let tempSub: Subscription = this.observable$.subscribe(value => { if (value === 'somethingSpecific') { tempSub.unsubscrib ...

Postman encountered a preflight failure on the Node API request

After calling the API from a browser, it successfully returns a correct response from the server: { "error": false, "message": "Hello World" }. However, when the same request is made using Postman, it results in an unexpected HTML content prompting to ena ...

Visit localhost:3000 to view the contents of localhost/myproject/index.html

Recently, I ventured into the world of node.js with the intention of grasping how to access the node.js port (3000) by simply typing the URL of the index.html. Following the steps outlined in this tutorial to build a chat application, I encountered an issu ...

Creating Immersive Web Pages

I am currently generating a large amount of data in HTML for periodic reporting purposes. The table consists of approximately 10,000 rows, totaling around 7MB in size. As a result, when users try to open it, the browser sometimes becomes unresponsive due t ...