How can I customize the border color and text color of the <TextField/> component in Material-UI without relying on makeStyles?

Can Material-UI be customized using traditional CSS instead of the makeStyles feature? I'm intrigued to learn more about the styling options in Material-UI.

I'm aiming to replicate the red style at the bottom using basic CSS techniques.

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

Answer №1

Explained below is a demonstration of how you can personalize the different colors in an outlined selection using basic CSS.

styles.css

.customSelect {
  width: 200px;
}
.customSelect .MuiInputLabel-root {
  color: red;
}
.customSelect .MuiInputBase-input {
  color: green;
}
.customSelect .MuiOutlinedInput-notchedOutline {
  border-color: red;
}
.customSelect:hover .MuiOutlinedInput-notchedOutline {
  border-color: orange;
}
.customSelect
  .MuiOutlinedInput-root.Mui-focused
  .MuiOutlinedInput-notchedOutline {
  border-color: purple;
}
.customSelectMenu .MuiMenuItem-root {
  color: blue;
}

App.js

import React from "react";
import "./styles.css";
import TextField from "@material-ui/core/TextField";
import MenuItem from "@material-ui/core/MenuItem";

export default function App() {
  const [value, setValue] = React.useState("");
  return (
    <TextField
      className="customSelect"
      label="Sale Type"
      required
      select
      value={value}
      onChange={event => setValue(event.target.value)}
      variant="outlined"
      SelectProps={{ MenuProps: { className: "customSelectMenu" } }}
    >
      <MenuItem value={1}>Sale Type 1</MenuItem>
      <MenuItem value={2}>Sale Type 2</MenuItem>
    </TextField>
  );
}

https://codesandbox.io/s/customize-textfield-via-css-jl2w2?fontsize=14&hidenavigation=1&theme=dark

Related answers:

  • Change border color on Material-UI TextField
  • Global outlined override
  • Change outline for OutlinedInput with React material-ui

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

Is it possible to create a responsive Material UI tab design?

How can I make the Material UI tab react component responsive? Check out the documentation for MATERIAL UI TAB here If I have multiple tab items with a search bar like shown below, how can I ensure that the input component stretches the whole width of th ...

Is there a way to implement the adjacent selector in combination with the :before selector?

Hello there, I am working on a timeline area with a slick effect and have implemented slick.js for that purpose. I am trying to change the color of my spans within the elements. Specifically, I changed the first span in the slick-active class element succe ...

Content Blocks with Added Cushioning

I am striving for the cleanest code possible. Can an article and an aside have padding, margins, etc? I have been struggling to achieve this. I find myself having to add a div with a class that accepts padding. article { width:463px; float:left; ...

Enhance the dimensions of images on Tumblr

Is there a way to customize the width of a photo in HTML? I am having trouble changing the size of a photo set on Tumblr to be larger. I have tried researching it, but I don't understand where to place maxwidth:600px or if this is even the correct app ...

Creating two interactive animations utilizing a combination of CSS and Javascript, triggered by the click event on

Looking to incorporate two unique CSS animations into my project. Utilizing two buttons and one object, I want the first animation to trigger upon clicking the first button. I understand how to handle one button and one animation, but am unsure how to man ...

What could be causing the issue with the theme not functioning properly in Material-UI?

I'm currently working on implementing a unique theme-switching feature in my web application, allowing users to toggle between light and dark modes. Utilizing the Material-UI framework combined with React, here's the code snippet: const theme = c ...

Ways to position a container div below a menu through CSS

I'm having trouble getting the container div to display below the menu instead of alongside the header. Can someone help me fix this issue? Here is my HTML and CSS code: <!DOCTYPE html> <head> <meta charset="utf-8" /> <title>R ...

Encountering a React.js issue when attempting to update data

When attempting to update fields with a given drugid, an error occurs. For example, selecting drugid as 1 and clicking the update button results in an error message stating 'localhost:8081/drug/1' not found. In the MongoDB database, there is also ...

Contrast data from two arrays and create a fresh array

I have two arrays that may or may not share similar values const arrayOne = [orange, red, black, blue, yellow] const arrayTwo = [blue, purple, white, red] Working with react, I aim to use useEffect to identify and return the unique elements when a change ...

Syncing state seamlessly between server and client using Redux toolkit with Nextjs version 13

Do we need to synchronize the state between the Next.js server and client side when using Redux Toolkit with Next.js 13? For example, on a User Page: If there's a flag isRedirect: false in the Next.js server state, and then the flag is changed to is ...

Maintaining the original layout upon refreshing the page

Incorporating two forms on my website, I added a button that transitions between the login and sign-up forms smoothly. The process is as follows: Initially, the login form is displayed; clicking the button switches to the sign-up form. Proceeding to subm ...

Is there a way for me to display a gif similar to 9GAG on my

I'm looking to implement a feature on my website that allows me to pause and play a gif, similar to the functionality on 9gag. Can anyone provide guidance on how I can achieve this? I understand that I need to use both .jpg and .gif files, but my at ...

What is the best way to persist my data on a page when I navigate to a different page in React.js?

Currently, I am utilizing Material UI tabs with 8 pages as components. Each page contains input areas, and when I switch between tabs, the data in the inputs gets cleared. I want to retain this data even when moving to another tab. How can I achieve this ...

As the div elements stack up and you scroll towards the top or bottom

I am dealing with two nested DIVs that are both scrollable. When I scroll the "inside div" (the green one in the attached file), and reach the bottom of the DIV, it starts scrolling the DIV beneath it. How can I prevent the DIV beneath from scrolling only ...

Unable to serve certain file extensions from the .NET Core local server even after making changes to the <requestFiltering> section in the applicationHost.config file

I am currently working on a website and encountering an issue with accessing/downloading certain file extensions such as .py and .cs. For instance, when attempting to fetch a .cs file, the following code is used: fetch("https://localhost:44310/userdat ...

How to position items at specific coordinates in a dropdown using JavaScript

I have five images in my code and I would like to arrange them in a circular pattern when they are dropped into the designated area. For example, instead of lining up the five images in a straight line, I want them to form a circle shape once dropped. Ho ...

Encountering an issue with retrieved items upon refreshing the webpage

My usual approach to fetching data from an external API involves the following steps: Using Fetch API: const [tshirts, setTshirts] = useState([]); const fetchData = () => { fetch('apiEndpoint') .then((response) => ...

Choosing a color while hovering over the navigation bar

I'm trying to modify the color of my navigation bar when hovering over it with the mouse. Currently, it's black but I want it to change to a light grey or white color. What am I missing here? HTML: <!DOCTYPE html> <html> <head ...

Is there a way to address the tar version in package-lock.json?

I am facing a similar issue to this problem on Stack Overflow: How can I resolve the high vulnerability in NPM package Tar related to Arbitrary File Overwrite, even though the package is updated? After installing node v17.2.0 and npm v8.2.0 using brew on ...

Unable to make API calls in React frontend due to CORS restrictions

Profile.jsx const fetchData = async () => { const response = await fetch(`http://localhost:5000/api/user/update/${currentUser._id}`, { method: "POST", headers: { "Content-Type": "application/json" }, body: ...