Modify the text field's color when it is in a disabled state

When the text field is disabled, I want to change its color. Below is the code I have written for enabled and disabled states. The style works correctly when the text field is enabled.

  const StyledTextField = styled(({ dir, ...other }) => <TextField {...other} />)`
  label.focused {
  color: green;
 }


.MuiOutlinedInput-root {

direction: ${props => (props.dir ? props.dir : "rtl")};
fieldset {
  border-color: white;
  background-color: rgba(2, 37, 67, 0.5);
}


&:hover fieldset {
  border-color: #87ceeb;
}
&.Mui-focused fieldset {
  border-color: rgba(0, 51, 96, 1);
}

  

fieldset  {
  border-color: white;
  background-color: rgba(2, 37, 67, 0.5);
  
  }
  }

 
}

.MuiOutlinedInput-root.Mui-disabled {
 
direction: ${props => (props.dir ? props.dir : "rtl")};
fieldset {
  border-color: black;
  background-color:black;
}


&:hover fieldset {
  border-color: black;
}
&.Mui-focused fieldset {
  border-color: black;
 }

  

fieldset  {
  border-color: black;
  background-color:black;
  
}

 
  }
    ${props =>
    props.center &&
   `.MuiOutlinedInput-input {
    text-align: center;
    }`}
   `;

  export default StyledTextField;

This is how my text field looks:

  <MyTextField
      id={props.id}
      name={props.id}
      className={props.classes.textField}
      value={props.value}
      onChange={props.onChange}
      margin="dense"
      variant="outlined"
      type={props.type ? props.type : "text"}
      error={props.error}
      fullWidth={props.width ? false : true}
      style={props.width ? { width: props.width } : {}}
      dir={props.dir}        
      inputProps={{ readOnly: props.disable }}
      label={props.message}
      disable={props.disable}
      
      
    />

And here's how I use it:

    <InputRow
                                id="qwe"
                                value={min_quality_threshold}
                                onChange={this.handleChange}
                                classes={classes}
                                disable={true }
                                
                            />

In the InputRow component, I set the disable prop to true to make it disabled, but the style of the disabled root does not change as expected.

Answer №1

If you want to style a disabled input using CSS, try this code:

input:disabled {
  background-color: lightgrey;
  color: darkgrey;
}

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

How to align all children at flex-start while positioning one child at the end?

I am currently working on a flex container that has 3 children. My goal is to have all the children align at flex-start, with the final child positioned at the bottom of the container. Can align-content be combined with align-self to achieve this layout? ...

List of prices with a dotted line separating the price and product, adjusting its width based on

I am attempting to create a price list with a dotted underline between the price and product that adjusts dynamically in width. Here is my code snippet: https://jsfiddle.net/romariokbn/2gm27rv6/ <ul class="how-can-i-do"> <li> <span ...

SliderToggle and Div implementation in Internet Explorer (IE) using jQuery

I'm encountering an issue with jQuery's slideToggle function and a div specifically in IE. Here is the code snippet causing the problem: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.d ...

Using React and Material-UI: Implementing button functionality to call another class using hooks in the main App component

Just starting out with React/MUI and currently working on different components for a website, so the UI is not a priority at the moment. Encountering an issue when trying to create a button that links to the Sign Up page (similarly for Sign In): Error: ...

React Native Issue: Missing propType for native property RCTView.maxHeight

Upon upgrading to RN 0.30, I encountered the error message below even when trying to build the most basic app: react-native init AwesomeProject react-native run-ios What's peculiar is that the warnings include components BlurView, VibrancyView, an ...

Swapping mouse cursor using JavaScript

Currently, I am working on a painting application in JavaScript that utilizes the Canvas Object. I would like to customize the mouse cursor when it hovers over the Canvas object. Can anyone advise me on how to accomplish this? ...

Access the value of a property within the same parent object in JavaScript using JSS

I am currently working with a material-ui AppBar component that is set to position="fixed," ensuring it remains at the top of the window as the main menu bar. This specific component is named "header" and is styled using the following JSS object. One issu ...

Position an element to the right inside its parent container with varying width in Internet Explorer 7 or earlier

I am trying to align a button to the right edge of a table inside a container-div that has no set width. The goal is to have the button float on the right side of the table, lining up with its right edge. While my current approach works in most browsers, i ...

Experiencing a problem with the localhost connection

I've been trying to work on this issue using React and local host, but it keeps showing the direct file instead of the website. I've been stuck on this problem for the past 3-4 hours and still haven't been able to find a solution. I'm h ...

Adjust the font color in code function for Woocommerce

I am looking to customize the appearance of a specific part of this code: '% discount' This section displays the percentage amount followed by the word "Discount," and I would like to apply a unique color to this "% discount" * Modify the disp ...

Tips for adjusting the background color of an ag-grid component in a React application

Looking to make a full background color change in ag-grid within a React application. Experimented with row cell style, but aiming for the entire grid background change. Here is my code snippet: { headerName: "Module Name", field: "ModuleName", ...

Shifted picture next to the accompanying words

I have successfully created a slideshow of images using JavaScript. <html> <head> <script language="JavaScript"> var i = 0; var path = new Array(); path[0] = "one.jpg"; path[1] = "two.jpg"; function swapImage() { document.slide ...

The infinite scroll feature seems to be malfunctioning in my react.js project. Despite implementing the infinite scroll component, the images from the next page are not being

I recently started learning React.js and I'm trying to implement infinite scrolling to fetch more images from the Flicker API, but for some reason, it's not working as expected. Currently, I'm using Material UI along with the Infinite Scrol ...

The never-ending scroll feature in Vue.js

For the component of cards in my project, I am trying to implement infinite scrolling with 3 cards per row. Upon reaching the end of the page, I intend to make an API call for the next page and display the subsequent set of cards. Below is my implementatio ...

error 404 when sending a xhr request in node and react js

I am currently developing a basic login page in React that needs to connect to a database through an AJAX call to a Node.js file. Here is the Node.js code I have implemented: var express=require('express'); var app=express(); var db=require(&ap ...

CSS3 Animation for Marquee Image

I'm struggling to create a CSS3 animation for an image. My goal is to have the image continuously wrap around and scroll across the page, but I can't get it to work as intended. Here's a simple snippet of my HTML: <div id="space" class=" ...

Creating an infinite loop animation using GSAP in React results in a jarring interruption instead of a smooth and seamless transition

I'm currently developing a React project where I am aiming to implement an infinite loop animation using GSAP. The concept involves animating a series of elements from the bottom left corner to the top right corner. The idea is for the animation to sm ...

Tips for widening cards using react-toolbox

Is there an expandable option available in the react-toolbox card component similar to material-ui cards? ...

Send an object to query when using Router.push in Next.js

Just getting started with NextJs and I'm experimenting with passing an object to another page through a component. Let me show you the code and explain what I'm attempting to accomplish: The object I want to pass looks like this: objectEx = { ...

Encountering a mistake due to the anticipated atom not being found at the specified

In my react application, I am encountering an issue with allowing foreign characters along with English in the input field of a form. I have implemented a regular expression as follows: const alphabetRegex = /^([A-Za-z]+ )+[A-Za-z]+$|^[A-Za-z]*\p{L}/g ...