How come I am unable to alter the border color in the input field of material-ui?

My goal is to change the input border color to white regardless of whether it is focused, hovered, or just by default.

I have attempted to create a theme using makeStyles for the text and input fields but it does not seem to be working. Here is my code:

const useStyles = makeStyles((theme) => ({
  textField: {
    '& .MuiOutlinedInput-root': {
      borderColor: 'white',
      '&:hover': {
        borderColor: '#ffffff',
      },
      '&.Mui-focused': {
        borderColor: 'white',
      },
    },
    '& .MuiOutlinedInput-input': {
      color: 'white',
    },
    '& .MuiInputAdornment-root': {
      color: 'white',
    },
  },
}));

This is how I am creating my textfields or input fields:

<TextField
          type="number"
          name={name}
          value={value}
          onChange={handleChange}
          InputLabelProps={{
            shrink: true,
            style: { color: 'white' },
          }}
          InputProps={{
            inputProps: {
              step: 1,
              min: 0,
            },
            endAdornment: (
              <InputAdornment position="end">
                {isForm && (
                  <>
                    <IconButton
                      aria-label="increase"
                      size="small"
                      onClick={() => handleChange({ target: { name, value: parseInt(value || '0') + 1 } })}
                      style={{ color: 'white' }}
                    >
                      <ArrowUpwardIcon />
                    </IconButton>
                    <IconButton
                      aria-label="decrease"
                      size="small"
                      onClick={() => handleChange({ target: { name, value: Math.max(parseInt(value || '0') - 1, 0) } })}
                      style={{ color: 'white' }}
                    >
                      <ArrowDownwardIcon />
                    </IconButton>
                  </>
                )}
              </InputAdornment>
            ),
            classes: {
              root: classes.textField,
            },
          }}
          sx={{ '& .MuiOutlinedInput-root': { borderColor: 'white' } }}
        />

Any suggestions on how to resolve this issue?

Answer №1

To address this issue, consider utilizing inline styling or the use of !important if your CSS styles are contained in an external file.

TextField
    label="Standard"
    variant="standard"
        sx={{
          '& .MuiInput-underline:before': {
            borderBottomColor: 'white',
          },
          '& .MuiInput-underline:hover:not(.Mui-disabled):before': {
            borderBottomColor: 'white',
          },
          '& .MuiInput-underline:after': {
            borderBottomColor: 'white',
          },
          '& .MuiFormLabel-root.Mui-focused': {
            color: 'white',
          },
        }}
      />

Begin by targeting the default bottom line: & .MuiInput-underline:before when there is no focus. Next, address the hovered underline with: & .MuiInput-underline:after. This step may be omitted based on your requirements. Finally, focus on the focused underline: & .MuiInput-underline:after, encompassing all 3 scenarios for comprehensive coverage.

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

Troubleshooting Steps for Resolving the TypeError 'ffmpeg.load() Failed to Fetch'

Struggling with creating a function to apply a text watermark on a video in Next.js using ffmpeg. Facing the same error repeatedly and clueless about resolving it. Error message: TypeError: Failed to fetch await ffmpeg.load(); No errors found in the c ...

Modify the array dynamically within the Factory

I am currently working on a simple app where I want to display embed videos with the click of a button. It was quite challenging for me to dynamically bind my embed players, but I managed to do it successfully. I created a factory that contains my data in ...

What is the best way to obtain root access and utilize disk usage (du) within the main process of Electron?

In the process of developing a macOS application with the help of Electron, I encountered an issue. Attempting to execute the following command from the main process using ipcMain and NodeJS's exec: // Navigating to a directory and utilizing disk us ...

The useId function in React 18 cannot be used as a key identifier

The issue at hand is that React Hook "useId" is being called inside a callback, which is not allowed. React Hooks should only be called in a React function component or a custom React Hook function. Now, the question arises - where can we appropriately u ...

The JSONP request connected to the user input field and button will only trigger a single time

Hello all, I'm new to this and have been searching the internet high and low to see if anyone has encountered a similar issue before, but haven't had any luck. I've been attempting to set up a JSONP request to Wikipedia that is connected to ...

Instructions for setting specific items to be checked when loading jstree. The "selected = 'selected'" method is not functioning as intended

In my MVC 4 project, I am using jstree for tree models. While the create operation works fine, I encountered an issue during the edit operation. I need to set the value to true for certain items in the treemodel. The models I am working with are as follows ...

Remove items from an array using JavaScript

My array, results = [duplicate, otherdup], holds a list of duplicates. Within my regular array, original_array = [duplicate, duplicate, duplicate, otherdup, otherdup, unique, unique2, unique_etc], how can I iterate through the results array and remove dup ...

Creating iterative headings in R Quarto HTML

I'm in the process of creating an innovative Quarto HTML document. My goal is to generate dynamic headings within the HTML code. I have managed to achieve the following successfully: {r} #| output: asis star_wars_data = data(starwars) TESTING <- ...

Pass the initial value from a parent component to a child component in ReactJS without the need for state management

Initially, I have a parent Component A that calculates an initial value for its child Component B. The initial value is computed in the componentDidMount() of Component A and passed to B using props: <ComponentB initialValue={this.state.value} handleCha ...

Obtain the API by navigating through nested dynamic routes in Next.js

Can someone help me with the folder structure in NEXT JS for pages/api/product/[id]/index.js? What would be the URL to access the Api index in the [id] folder? Here is my folder structure pages/ api/ product/ [id]/ index.js I nee ...

Include an HTML attribute within a given string

Using jQuery, I am adding HTML content to a div. The variables rowString and inputString have been defined beforehand: $("#filterContainer").append( rowString + `<label class='filterLabel' for=${filter}>${filter}< ...

Stop a div at a specific point with this unique jQuery plugin

I am looking to implement a similar feature on my website that can be seen here: The desired functionality is when a link stops at a certain point while scrolling, and upon clicking the link it smoothly scrolls to a designated div. Additionally, as you sc ...

Executing callback function within Observable.prototype.subscribe in Angular 2

Having issues with the complete callback not functioning as intended. Here's a breakdown: Take a look at this image and note the complete callback within the subscribe method. The complete function is only triggered when observerOrNext is called. If ...

The functionality of the Hubot script is restricted to Slack conversations where I initiate a direct message with the

At this very moment, my automated Hubot assistant is functioning properly. When I send the following message via direct message to the robot in Slack: qbot !npm bower The response provided by the robot contains a link: https://www.npmjs.com/package/bowe ...

React/MaterialUI - Is there a way to customize the placeholder text for my multi-input field beyond the provided options?

I have a dropdown menu that accepts two JSON objects, symbol and company. export default function SymbolInput() { const [data, setData] = useState({ companies: [] }); const classes = useStyles(); useEffect(() => { Axios.get(" ...

Node does not recognize the $or operator

Currently, I am enrolled in an online course and facing a problem with a query issue. Interestingly, the query functions perfectly fine in the shell, however, when executing the js file, an error arises stating: unknown operator: $or. Here is the crucial c ...

The functionality of Tailwind CSS Utility Classes is not functioning as expected

Currently, I am working on developing a replica of Airbnb using nextjs and tailwindcss within the VS code environment. Despite my efforts, I have encountered an issue where the utility classes are not functioning properly. The logo that was integrated in ...

What is the best way to position the list element to align with the top of a div container?

To see a live example, visit this link. My goal is to create a line that separates two li elements within a nested ul. However, the line ends up taking the width of the container ul instead of the div containing the entire structure. In the provided examp ...

positioning a div based on the location of another div

I am currently working on aligning a div that sits at the bottom of all other divs. The last div is set to float and aligned at the top using CSS. I am unsure how to align it from the left side without any issues when the screen resolution changes. Is th ...

Efficient Loading and Smooth Scrolling with Angular2 (version 7)

I'm struggling to display a component upon the initial page load using lazy loading, where the content is only loaded when it's in view. For instance: - With 10 components on the page, I aim to show/scroll to component number 7 when the page lo ...