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

What is the most effective method for integrating a hosted React application into a website that is not built using React?

I currently have a complete React application hosted on AWS that I want to embed into another non-React site. Right now, I have it embedded using an iframe and it's working well. <!doctype html> <html lang="en> <head> <meta c ...

What impact does CSS scaling transform have on the flow of a document?

I'm really confused about the impact of scaling an element using CSS transforms on the document flow. Take a look at this jsbin or this codepen (since jsbin seems to be down), where I have set up the following structure: p{slipsum text} #scaled #s ...

Dealing with a frustrating roadblock in Three.js where you encounter an "Unknown format" error while trying to work with

Greetings, I am relatively new to THREE.js and currently experimenting with loading a .FBX Object using the FBXLoader found in three/examples/jsm/loaders/FBXLoader while integrating this into React.js. Upon launching the page, I encountered an issue where ...

Interact and share information between Material UI components in React

Utilizing Material UI's nested/select ItemList component, I have created a dynamic dropdown menu that generates multiple items based on the content of the header. The mapping function in the code helps to render these items. In another file situated o ...

To enhance user experience, consider incorporating a 'Next Page' feature after the completion of every four paragraphs,

Here is a code snippet that can be used to print 'n' number of paragraphs: <% while(rs.next()){ String para=rs.getString("poems"); %> <p> <%=para%> </p> <!-- n number of p tags are printe ...

I am having trouble using sass files with the command 'dotnet new react'

I attempted to create an ASP.NET Core application with a React frontend, so I executed the following command: dotnet new react -o <project name> This generated a runnable project. However, the issue arose when it couldn't handle sass files. To ...

Step-by-step guide to implementing a month and year date-picker in Mozilla Firefox

I'm looking to create input fields where users can add the month and year. I tried using the code below, but unfortunately Mozilla Firefox doesn't support it. <input type="month" id="start" name="start"> Does ...

Navigate through information within designated boundaries

In order to achieve vertical scrolling of a sidebar div and its content (3 links) between two points, I have utilized the CSS property position:fixed; top: 100px. While this setup works well initially by positioning the sidebar 100px down from the top and ...

Is there a way to adjust the positioning of a MUI Popover component in relation to an anchorEl?

By using the anchorOrigin property, I can apply an offset to a MUI Popover using anchorPosition.top and anchorPosition.left. However, this adjustment does not work when attaching the popover to an anchorEl (connecting it to a trigger element) instead of an ...

React/Redux Web Applications Hosting (front-end)

I'm grappling with something at the moment. Consider a scenario where I have developed a website or single-page application using React/Redux. Let's assume that there are no API calls involved, meaning it's solely focused on the front-end as ...

Automating the logout process in React when a JWT token expires

One of my projects consists of 5 pages where I have stored a JWT token in local storage. In which screen should I implement the code for automatic logout and what will be the React code? App.js <BrowserRouter> <Switch> <Route exact pa ...

Are you integrating material-ui with redux?

Currently, I am rendering the main component in the following way: ReactDOM.render( <Provider store = {store}> {getRoutes(checkAuth)} </Provider>, document.getElementById('app') ) The documentation sug ...

Highlight the navigation transition in the menu

Is there a more updated tutorial available for creating an underline effect that slides from one link to another when hovered over and remains at the clicked link? I have come across a tutorial on Underline transition in menu which seems to be based on th ...

React warning: Make sure every child element in a list has a distinct "key" property assigned

Here is a breakdown of my code that consists of 2 components and index.tsx: NewsFeed.tsx import React, { useState } from 'react' import Feeds from './Feeds' export default function NewsFeed({ news }: any) { const [date, setDate] ...

Using Console.log() will display 'undefined' prior to receiving any data

I am facing a problem with a lifecycle hook that I have been trying to troubleshoot. export default class EditRevision extends Component { state = { data: [], customColumns: [] } componentWillMount = () => { axios.get('http:/ ...

Positioning Multi-level Drop Down Div in Javascript - How to do it efficiently?

I'm currently working on a horizontal menu using CSS and JavaScript with multiple levels. I've implemented a toggle function to show the submenu container, but it's causing the links below it to be pushed down. Is there a way to make the dis ...

Creating an app using Ionic 1 that features scrollable tabs with the ability to handle overflow

My current code snippet is displayed below. On smaller mobile screens, all 7 tabs are not visible at once and instead appear in two rows which looks messy. I want to modify the display so that only 3 tabs are visible at a time and can be scrolled through. ...

Trouble with the fetch request on the express root router when trying to connect with React

I am facing an issue while attempting to call the root router ('/') of Express using fetch API in React in production mode but it seems to be not working as expected. In my setup, I am utilizing a common server for serving static React views and ...

Personalized dropdown appearance

During my work on a select box, I discovered that custom styling is not possible. I attempted to use some plugins but did not find one that met my needs. I am seeking a dropdown menu with options in both black and gray, similar to this template but using ...

How can I identify the main text of a specific <MenuItem/> component in ReactJS Material-UI?

I've been working with the Material-UI Dropdown Menu component and I'm trying to figure out how to console log the primaryText of the selected <MenuItem/>. Can anyone provide guidance on how to achieve this? ...