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

Creating a time-limited personal link with Django Rest Framework and React

I have a frontend application built with React Framework that I want to provide access to via a time-limited personal link, without the need for additional authentication functions. With approximately 1-2 new users per day, my proposed implementation is as ...

Utilizing a map loop to efficiently exchange information among various components

Attempting to transition from one component to another, with the second component requiring only one item from the array of the first component The issue arises when the second component iterates through the entire array up to the last element and display ...

Guide on adding CSS3 ribbons to elements on both sides

I recently came across a tutorial that teaches how to create a CSS ribbon. However, after following the tutorial, I found that the ribbon only appears on one side of the element. This has left me wondering if it's possible to have the ribbon display o ...

The menu in IE7 seems to have a mind of its own, appearing and

Having trouble with my menu displaying correctly in IE7. It seems to be a stacking issue: the menu initially appears but disappears once the header image and rest of the page load. I've tried adjusting the z-index values in both the menu and its paren ...

I am experiencing issues with using props data in the componentDidMount method in react-native

I have been grappling with this issue for the past day. The challenge lies in passing props from my parent class and accessing the data in my child component. While the data displays correctly when rendered, it appears as null when called in componentDidMo ...

Ensuring a logo remains centered and stable even when the browser is resized

How can I ensure that this logo remains fixed at the center top of the page, without moving as the browser size changes? I want the logo to maintain its position and not recenter itself when the browser is resized. Below is my current CSS CSS #logo { p ...

Utilizing jQuery or Javascript to obtain the title of the current webpage, find a specific string within it, and then apply a class to the corresponding element

Let's imagine I start with this: <title>Banana</title> and also have some navigation set up like this: <ul id="navigation"> <li> <a href=#">Banana</a> </li> </ul> Upon loading the sit ...

Tips on resizing images within a container to maintain aspect ratio

I am trying to create a layout with a flex container containing 2 divs - one with an image that floats left, and the other with some paragraphs floating right. How can I make sure that the image scales alongside the paragraphs while maintaining its aspect ...

Encountering a frustrating issue trying to submit a React form with Next and Prisma due to a pesky 500 error

Whenever I try to submit a comment on a blog article using a form, I keep getting an error 500 and I can't seem to figure out why. I attempted to modify the route that is being called, but I'm not certain if that's the root cause of the iss ...

Stylish CSS menu design

I am struggling to set up a top menu bar using float: left. How can I achieve the desired behavior for a top menu bar? The code snippet below demonstrates what I have tried so far: * { margin:0; padding: 0; } #menu { background-color: yell ...

Experiencing discrepancies in pixel height while conducting tests using Nightwatch

Let me start by sharing some details about my machine setup: Operating System: CentOS 7 Graphics Drivers: kmod-nvidia (dedicated GPU) I am currently testing a webpage using Nightwatch, and one of the requirements is to ensure that a background image&apo ...

Disallow the generation of React components

I have a piece of code that successfully generates a to-do list, but I'm facing an issue. Even when I accidentally submit an empty form, new elements are still being created. How can I use useState to display a message preventing the submission of emp ...

Struggling with organizing the layout of your HTML page? Let us lend

I am having difficulty with the layout of a page I'm working on. The lower page navigation is not positioning properly - it wraps below the left column instead of staying below the data columns. Additionally, the border for the navigation appears at t ...

What steps can I take to ensure that this input is neat and tidy

I need to implement conditional styling for my input field. The current layout is chaotic and I want to improve it. Specifically, when the active item is "Height", I only want to display the height value and be able to change it using setHeight. const [a ...

What steps should I take to create this animation?

So here's my concept: I envision a circle div positioned in the center with multiple small lines extending outwards, resembling rays of sunlight. How should I go about achieving this effect? Would implementing JavaScript or utilizing CSS3 animations b ...

Tips for modifying the color of selected text

Is there a way to change the color of the dropdown text? Currently, it is set to red but initially appears as black. When clicked on, it changes to red. How can I make it so that the color is initially displayed as red? <select> <option style ...

Firefox encounters a border-radius glitch

Having an issue with the border-radius function in Firefox. After applying it, I notice a strange space or border around the item. Does anyone know if this is a bug specific to Firefox or if there is a solution for it? Here is an example of the problem: J ...

Ways to retrieve the React Router match object in mapStateToProps

Is there a way to access the react-router match object for its params from mapStateToProps or any other selector? I'd like to use these params to generate a value that will be passed down as props to a presentational component within the selector. The ...

The URL retrieved on the React client-side does not align with the URL that was originally requested on the server

Currently, I'm developing a small app using nodejs-express-react. The issue I'm facing is related to sending a request to the Google Analytics Management API server-side and then attempting to retrieve the response from the client-side. Unfortuna ...

Move buttons from one group to another group

I have a task to update a group of buttons with different buttons depending on the initial button chosen. Button1: when clicked, both buttons will be replaced by Button1a and Button1b Button2: when clicked, both buttons will be replaced by Button2a ...