Unable to modify the border color of the outline in MUI text fields

I am currently working on a React project using MUI and styled-components, but I am facing an issue with changing the outline border color of a textfield. Despite reading the documentation and attempting to overwrite the class names of the component, it does not seem to be working as expected.

Below is the styled-component code for the textfield:

export const LoginField = styled(TextField)`
  margin-top: 10px !important;
  width: 100% !important;
  border-color: ${(props) => props.theme.text.primary}!important;

  & .MuiInputLabel-root {
    color: ${(props) => props.theme.text.primary};
  }

  & .MuiOutlinedInput-root {
    border-color: ${(props) => props.theme.text.primary};
    
  }

  & .MuiOutlinedInput-root {
    & fieldset {
      border-color: red,
    },

  & .MuiSvgIcon-root {
    color: ${(props) => props.theme.text.primary};
  }
  & .MuiFormControl-root {
    color: ${(props) => props.theme.text.primary};
  }

  // Mui bug where it changes the background of the input on autofill
  input:-webkit-autofill,
  input:-webkit-autofill:hover,
  input:-webkit-autofill:focus,
  input:-webkit-autofill:active {
    transition: background-color 5000s ease-in-out 0s,
      color 5000s ease-in-out 0s;
    transition-delay: background-color 5000s, color 5000s;
  }
`;

It's interesting that this customization works for all classes except .MuiOutlinedInput-root, which is causing the issue. Despite checking multiple sources confirming it as the correct class name.

The textfield implementation in my React component:

<LoginField
  variant="outlined"
  label="E-mail"
  type="email"
  value={email}
  onChange={handleEmail}
  InputProps={{
    startAdornment: (
      <InputAdornment position="start">
        <Person />
      </InputAdornment>
    )
  }}
/>

Since I have custom themes for light and dark modes, I utilize theme props to dynamically set colors.

I have also attempted another solution:

export const LoginField = styled(TextField)({
  "& .MuiOutlinedInput-root": {
    "& fieldset": {
      borderColor: "white",
    }
  },
});

While this successfully changes the border color to white, it lacks the ability to use custom theme props and maintain consistency across styled-components. My goal is to ensure uniformity across all components, which the above solution fails to achieve.

Answer №1

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active  {
  -webkit-box-shadow: 0 0 0 30px white inset !important;
}

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

The issue of anchor links (#) not functioning properly when navigating within the same page of a Next.JS app router

I've encountered an issue with the <Link/> component in my Next.js app. I've set the href to #targetDiv, expecting the page to scroll to the corresponding section with the id #targetDiv upon clicking. However, this functionality is not work ...

An issue occurred when serializing `something` retrieved from the getServerSideProps function on a certain page

Currently, I am in the process of developing a project utilizing next.js. In this particular project, there is a dynamic route that makes use of getServerSideProps. It allows for passing queries to the page with the folder structure set as category/[title] ...

Firebase Function deployment encountered an issue during the build phase, despite the predeploy process

My react.js project includes Firebase functions that are configured in a sub-folder called root/functions. These functions are written in typescript and have paths option set in tsconfig.json. In my functions/index.ts file, I import files from various loca ...

Unable to locate React.js refs within object

import { Button, Form, FormGroup, Label, Input, FormText } from 'reactstrap'; export default class UserPicForm extends React.Component { constructor() { super(); // establish bindings this.handleSubmission = this.handleSubmission ...

JavaScript form validation problem: Warning for identical responses in the MOST and LEAST sections

I've encountered a challenge while working on an HTML and JavaScript form for a personality test. The issue revolves around validation, particularly when the form includes multiple questions with both "MOST" and "LEAST" radio button options. One spec ...

What is the best way to align three tables columns in a single row?

I am facing an issue with aligning the columns of three different tables in one line. I have tried applying CSS styling, but the columns still appear misaligned. How can I ensure that the columns are properly arranged in a single line? Below are my HTML/C ...

Tips for incorporating external JavaScript code into React components

I have been tasked with integrating a graphical widget into a React component for a project I am working on. The widget_api code provided by RIPE Stat is required to accomplish this. Previously, in HTML5, the integration was successful using the following ...

Issue: The module 'eslint/lib/rules/no-unused-expressions' could not be located

Since I installed ESLint using NPM, an error is popping up in my browser that says: Error: Unable to locate module 'eslint/lib/rules/no-unused-expressions' Referenced from: Does anyone have any clue as to why this is happening and how I can ...

Adjusting font size, contrast, brightness, and sound levels on a website with the help of jQuery

My client has a new requirement: adding functionality to increase font size, adjust contrast/brightness, and control sound on his website. When clicking on any of the control images, a slider should appear for the user to make adjustments accordingly. Ho ...

What steps can I take to re-open the Snackbar?

Recently, I developed my own Snackbar component. import React, { Component } from 'react'; import { Snackbar, IconButton } from '@material-ui/core'; import CloseIcon from '@material-ui/icons/Close'; interface AlertProps { ...

Issue with MaterialUI value prop not updating after dynamic rendering of components when value state changes

As I dynamically generate Material UI form components, I encounter an issue with updating their values. The value prop is assigned to a useState values object, and when I update this object and the state, the value in the object changes correctly but the M ...

"Utilize the parent component's functionality by extending/inheriting it

export default function PageTemplate() { return ( <div className="layout"> <LeftMenu /> <div className="content"> <TopMenu /> <div id="other-contents"> ...

Using the react-router Navigate component within a Next.js application allows for seamless

Is there a way to achieve the same result as the Navigate component in react-router within Nextjs? The next/Router option is available, but I am looking for a way to navigate by returning a component instead. I need to redirect the page without using rout ...

Print the value of the React MaterialUI Select MenuItem component when no selection has been made

I am currently delving into the world of React and have started using Material UI in a project. One of the components I created is a Select MenuItem component where I passed an image as a value. The functionality I am aiming for is that when a user selects ...

How can I create and assign types dynamically in TypeScript?

I'm working on creating an SX styling file with a style object of type SXPropsTypes. In another file, I'm having trouble accessing the style properties because the autocomplete isn't suggesting the keys of my style object. style.ts import { ...

Navigating to the bottom of a specific element by scrolling

I am currently working on enhancing a module within the application I'm developing. The goal is to automatically scroll the browser window to the bottom of an element when said element's height exceeds the height of the window. The functionality ...

Testing the scope of Jest unit coverage for the jQuery AJAX function

I am looking to test the $.ajax method within my React component using Jest and Enzyme for unit test coverage. $.ajax({ url: `url`, type: "GET" }).done(data => { //dosomething }).fail(err => { //do something else ...

Attempting to link various functions in my component consecutively

Attempting to link numerous actions together in my react component poses a challenge: componentDidMount() { dispatch(Actions.fetchUser(userId)).then(() => { dispatch(Actions.fetchAbc(abcId)).then(() => { dispatch(Actions.fetchDef(defId)) ...

Positioning two buttons side by side in separate columns on the same horizontal alignment

My objective is to arrange these two buttons horizontally on the same level with the help of bootstrap. <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href ...

The car glides smoothly across the screen from left to right before disappearing from view

I'm looking to create an animation where a car moves from left to right and then switches to another image moving from right to left. Can anyone provide assistance with this task? Here's the code I have so far: .car-movement { position: a ...