Learn how to customize the border color on Material UI textfield when in a focused or error state

I've been struggling to change the color of the text field input when both the error and focused classes are active. Despite trying various styles, I just can't seem to get it right. Can someone help me identify which class I need to target? I'm relatively new to Material UI

import { TextField } from "@mui/material";
import { styled } from "@mui/material/styles";
import "../shared/variables.css";

export const ContactInput = styled(TextField)(() => ({
  fontFamily: "Open Sans, sans serif",
  fontWeight: 700,
  "& MuiInputBase-root": {
    fontWeight: 700,
  },

  "& label": {
    letterSpacing: "1px",
    color: "var(--fontMainColor)",
    fontWeight: 600,
  },

  "& label.Mui-focused": {
    color: "var(--fontMainColor)",
    fontWeight: 600,
  },
  "& label.Mui-error": {
    color: "var(--error)",
  },

  "& .MuiOutlinedInput-root": {
    "&.Mui-focused fieldset": {
      borderColor: "var(--fontMainColor)",
      fontWeight: 600,
    },
  },

  "&.MuiOutlinedInput-notchedOutline": {
    fontWeight: 700,
  },

  "&.Mui-error .MuiOutlinedInput-notchedOutline": {
    borderColor: "green",
  },
}));

https://i.stack.imgur.com/QlK1S.png

Answer №1

After much searching, I finally cracked the code. The key was to include this specific selector:

  "& .MuiOutlinedInput-root": {
    "&.Mui-focused fieldset": {
      borderColor: "var(--fontMainColor)",
      fontWeight: 600,
    },
    "&.Mui-error fieldset ": {
      borderColor: "var(--error)",
    },
  },

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

Trouble with Nested Routing in React Router Version 6: Route not Rendering

I'm facing issues nesting a path within another path in react-router-dom version 6. When I try to visit the nested argument's page (/blog/1), it shows up as a blank non-styled HTML page. However, when I add a child path to the root like /blog, it ...

Preserve the checkbox state upon refreshing the page

I am facing an issue with keeping the checkbox state saved after a page reload. Currently, I have stored my unchecked checkboxes in localStorage, but I am unsure about what steps to take next. In simple terms, I want the checkbox to remain unchecked when I ...

Delete the text in MUI's TablePagination component that displays the number of rows per page and the total rows in the table

Currently, I am integrating MUI's tablePagination component into my React table with TypeScript. I am looking to remove/disable the circlemarked text displayed in the image (the picture is an example from MUI). https://i.stack.imgur.com/ib0t2.png Af ...

What is the process for obtaining a client-side cookie using next.js?

I'm currently facing an issue where I can't seem to maintain a constant value for the isAuthenticated variable between server-side and client-side in next.js. In my setup, I am using a custom app.js file to wrap the app with Apollo Provider. The ...

await for specialized Redux middleware

Can you explain the process of utilizing await inside a custom middleware function? const handleCustomMiddleware= (store) => (next) => (action) => { if(action.type === 'Start'){ const apiData = await fetchFromApi; } const updat ...

How should the main content be arranged with appbars and drawers in material-ui for optimal layout?

When working on React apps, I often rely on material-ui. Currently, for a project where I am utilizing the responsive drawer and appbar components, I am unsure about how to effectively position content around these navigation elements. Should I simply add ...

What is the more efficient approach: retrieving all data in one request or making individual requests for each piece?

When it comes to performance, which method is more efficient: 1) Retrieving 100 records in a single fetch request 2) Fetching each data row individually (100 times) P.S. I am using the axios library ...

Are there any techniques for enabling horizontal scrolling on the MaterialTable to handle overflow?

I am currently utilizing the MaterialTable component from the material-table library. I would like to make the table scrollable on the x-axis to accommodate a large number of columns. Below is the code snippet: <MaterialTable title="Members Acc ...

What are the different ways to customize the indicator color of React Material UI Tabs using hex

Just got my hands on this amazing Material UI component <Tabs textColor="primary" indicatorColor="primary" > <Tab label="All Issues"/> </Tabs> The documentation states that indicatorColor and textColor can only be set to ' ...

Single SPA encounters a clash of Material UI themes

I am currently working on loading two React micro front-end applications within a single spa. However, I am encountering issues with style conflicts related to the theme. Within the index.ejs file, there is a systemjs-import map section: <script type=& ...

How to access a variable from a separate component in NextJS

I have a variable stored in one component that I need to access in another component within my NextJS application. How can I achieve this? Component/Question.js import { useState } from "react"; function Questions() { const [question, set ...

Windows authentication login only appears in Chrome after opening the developer tools

My current issue involves a React app that needs to authenticate against a windows auth server. To achieve this, I'm hitting an endpoint to fetch user details with the credentials included in the header. As per my understanding, this should trigger th ...

Error message received: `TypeError: _this.props.setCurrentUserHandle is not defined in mapDispatchToProps for Redux`

I'm encountering a strange error while trying to make a simple react-redux app work. Specifically, I am struggling with setting my current user's first name and handle in the store using two set functions - one works, but the other doesn't. ...

What is the best way to customize the renderItem method in React Native's SectionList to be based on sections instead of

I've been exploring the FB docs and came across a mention of being able to override the default item-based renderItem method with a section-based render in the SectionList component in React Native. However, I'm struggling to find a way to actual ...

I tried utilizing the useState hook to store the value, but surprisingly, it failed to update

I am brand new to Reactjs and currently working on creating an address form that includes 3 select options for country, state, and city. I have implemented React hooks in my project, where the page fetches a list of countries upon initial load. Subsequentl ...

Tips for adjusting the content direction of a Popover

I am currently working on a component that includes the following code: import { Popover, PopoverTrigger, PopoverContent, PopoverBody, Portal, Button, } from "@chakra-ui/react"; import { ReactNode } from "react"; import { Co ...

Adjustable Size for Card Design

Here's the current setup of my component: <Card> <CardMedia> <img src="http://images.memes.com/character/meme/evil-toddler"/> </CardMedia> </Card> I've observed that the image is taking up ...

Difficulty arises when Jest tests struggle to interpret basic HTML tags within a React Component

When running test runs, issues arise when using standard HTML tags with Jest. My setup includes Babel, Webpack, Jest, and React Testing Library. To enable jest, I have installed a number of packages: "@babel/plugin-proposal-class-properties": "7.8.3", "@ ...

The function module.exportDefault does not exist

It seems like I am facing a unique issue with Meteor that I haven't come across before. Running on various versions like Meteor 2.0-beta.4, as well as Meteor 1.11 and 1.12, after setting up the app with a fresh checkout and executing "meteor npm inst ...

Currently, I am creating a regular expression to manage a specific task, but I have hit a roadblock in

Criteria: The string must not contain any uppercase letters. Special characters such as '^$.?*+()' are not allowed in the string. If the string includes '[', it must be followed by zero or more characters other than '[' and & ...