Is it possible to change a Material UI style without resorting to an HOC?

Is there any method to modify the styling of a Material UI component without the need to create an entirely new component using withStyles()?

For example, if I am currently displaying the following and simply want to adjust the color of the "Delete" label:

<div style={styles.rowFooter}>
  <FormControlLabel
    control={<ClearIcon />}
    label="Clear"
    title="Clear all fields."
    onClick={clearFields}
  />
  <FormControlLabel
    control={<DeleteIcon />}
    label="Delete"
    title="Delete this row."
    onClick={deleteRow}
  />
</div>

In order to achieve this, typically I would need to:

  • Create a new styling function that returns { color: "maroon" }.
  • Create a new component specifically for rendering the "Delete" button.
  • Apply my custom styles by calling
    withStyles(newStylesFn)(MyComponent)
    .

However, I am seeking an alternative solution. Is there any way to accomplish this without going through those steps?

Update:

One approach I am aware of is to use a CSS className. However, I was hoping for a different option as it does not work in this particular scenario to override the nested element.

I would prefer to be able to directly pass style={{ color: "maroon" }}, but unfortunately, this only changes the color of the icon itself and not the text of the label...

Answer №1

If you want to customize the styles provided by Material UI, consider using the classes prop instead of className.

<FormControlLabel
  control={<DeleteIcon />}
  label="Delete"
  title="Delete this row."
  classes={{
    label: 'labelStyle'
  }}
/>

styles.css

.labelStyle {
  color: maroon !important;
}

While not a perfect solution, it gets the job done without the need for withStyles().

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

Unable to display image between two inline-table divs while using Bootstrap

I'm currently developing a website for trading in-game items, but that's not important right now. The code snippet I am working with is: <div class="trade"> <h6><strong>RaiZeN</strong> wants to trade: (5 minutes ...

reactjs search bar with filtered results

Having an issue creating a search bar in reactjs. // Here is the endpoint structure export const getCountPoiCategoryProvinsi = (provinsi) => { return new Promise((resolve, reject) => { axios .get( `${baseUrl}/api/dashboard/v1/get ...

Can you modify the color of the dots within the letters "i"?

Is there a method to generate text like the one shown in the image using only css/html (or any other technique)? The dots in any "i's" should have a distinct color. Ideally, I'd like this to be inserted via a Wordpress WYSIWYG editor (since the ...

List in React without any unique identifiers

I have a list of numbers that I need to display in a table format. These numbers are fetched from an API call and not generated within my application. The data might change occasionally, but there are only around twenty values, so redrawing the entire tab ...

Is there a way I can decrease the width of the input field on the left side?

body { background: white; font-family: 'Ubuntu', sans-serif; } .cas { display: inline-block; border: 2px solid #0C8346; background: #0C8346; font-weight: 300; font-size: 20px; padding: 5px; width: 200px; text-align: center; ...

In React Js, the Owl Carousel is able to extract data directly from an array for seamless

Hey everyone, I'm working on rendering owl carousel images and content data sourced from an array. Here's a snippet of the data array: const MOVIEBANNER = [ { id: 1, genres: "ACTION / ADVENTURE", language: "ENGLISH, HINDI", ...

Next JS and the power of media queries

I've been searching for a while now, but I just can't seem to find a solution to my problem. I'm attempting to utilize different files for my media query breakpoints in Next JS, but they don't appear to be working. I created the files ...

Are your macOS devices not displaying the Scrollbar CSS buttons correctly?

I need help troubleshooting why my buttons are not appearing in the scrollbar on macOS. They function properly on Windows, so I suspect there may be a typo or error in my code. Can anyone take a look and provide some insight? ::-webkit-scrollbar { wid ...

Footer content spilling out of the wrapper div

My web page has a footer content that is overlapping the wrapper div due to some issues with my css and html. Even when I tried changing the height to auto, it didn't resolve the problem. Below is an example of the current state of the page I am worki ...

How does the use of nodejs, a server-side scripting language, tie into ReactJs or other front-end languages?

Can Node, being a server-side scripting language, be effectively utilized in the development of front-end applications such as npx create-react-app or npx create-nuxt-app? ...

Troubleshooting issue: Next.js Material-ui CSS SSR not functioning properly within components

Upon completing my project, I discovered that SSR for Material-ui is not functioning on the page where I utilized functional components. Here is my _document.js file: [Code from _document.js] Example Page: [Code from E ...

What is the best way to apply a specific style based on the book ID or card ID when a click event occurs on a specific card in vue.js

My latest project involves creating a page that displays a variety of books, with the data being fetched from a backend API and presented as cards. Each book card features two button sections: the first section includes "ADD TO BAG" and "WISHLIST" buttons ...

Navigating to the previous page in a Next.js 14 application with the App Router

Recent discussions have mainly focused on the Pages router. I am aware that with react router, I can achieve the following: const history = useHistory(); const { pathname } = useLocation(); history.push('/', { from: pathname }) Subsequently, I ...

Is there a way to perfectly center this image with the rest of my text content?

Seeking assistance in aligning this image to the right alongside other text content. Currently, when the code is executed, the image is pushed down and positioned below the text on the right side. Ideally, I would like the image to be aligned evenly with ...

Utilizing Three.js to Upload Images and Apply Them as Textures

While attempting to upload an image via URL and set it as a texture, I encountered an issue. The error message THREE.WebGLState: DOMException: Failed to execute 'texImage2D' on 'WebGLRenderingContext': Tainted canvases may not be loaded ...

"Exploring the features of next-auth server-side implementation in the latest version of Next.js,

Is it possible to utilize next-auth in a Next.js 14 application router to access user sessions and display page responses using SSR? If so, what steps need to be taken? ...

``There seems to be a problem regarding the alignment of elements in

Having some trouble with centering the grid on my simple website. As a beginner in Bootstrap, I'm seeking guidance. Will be grateful for any help you can offer! Please bear with me as I learn. <html> <head> <meta charset="utf8"/& ...

Issues with security vulnerabilities arise during the upgrade of react-scripts when utilizing npm upgrade and npm audit fix

Whenever I run npm upgrade or npm upgrade react-scripts, I always receive the following message: added 84 packages, removed 249 packages, changed 428 packages, and audited 1245 packages in 57s 179 packages are looking for funding run `npm fund` for deta ...

Having trouble getting jQuery JavaScript to work on Wordpress and feeling lost about how to implement no-conflict mode syntax

Trying to implement the code from this Codepen http://codepen.io/eternalminerals/pen/qdGvMo on my WordPress website at I understand that since WordPress is in no-conflict mode, I need to change $ to jQuery. I have made this adjustment and ensured that the ...

Eliminate any excess space to the right of the image

Utilizing Bootstrap alongside React, I've encountered an issue with images causing unwanted whitespace to the right. I've thoroughly examined the elements but have been unable to resolve this issue. Despite researching Bootstrap Col online, the ...