Adjust the borderBottomColor of Material-UI TextField upon completion of input

When working with MUI to create a form, I noticed that the default TextField bottom border is grey, turns blue when focused, and then back to grey when focus is lost. My goal is to prevent it from losing the blue color after filling in the field:

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

I attempted the following code snippet, but unfortunately, it did not work as expected:

.MuiInput-underline:after {
    border-bottom: 2px solid rgb(17, 0, 172);
}

Answer №1

Resolved the issue by incorporating conditional styles into TextField using the sx prop.

     sx={{
      "& .MuiInput-underline::before":
        textInputValue !== ""
          ? { borderBottomColor: "blue" }
          : { borderBottomColor: "grey" },
    }}

Answer №2

New Mui version 5 response

sx={{
    '& .MuiInputBase-root.MuiFilledInput-root:before': {
      borderBottomColor: 'blue',
    },
}}

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

Managing image alignment in flexbox containers with nested rows and columns

In the following design demonstration, there are three blocks to explore. Block 1: Consists of three columns. The middle column contains two rows, both set to flex:1. Block 2: Also has three columns. The middle column includes two rows, but with a unique ...

The accuracy of IE9 <section> is not quite up to par

When viewing This Page in IE9, the element section#tcs-website-content appears as 990px wide even though its CSS property is set to width: 100%. This occurs despite all parent elements also having a width of 100%, resulting in a browser width of 1024px. A ...

Issue with close request on dialog box

Whenever an icon is clicked, a dialog box containing a form should appear. The purpose of this dialog box is to either add a new tab or delete a specific tab. In my implementation, I used ReactJS, Redux, and Material-UI for building the components. Even th ...

Learn how to pass an id from the query parameters to the getInitialProps function in Next.js

Looking to create a basic website that displays content from a database? Utilizing the getInitialProps function from Next.js documentation can help with server-side rendering: https://nextjs.org/docs/api-reference/data-fetching/getInitialProps#getinitialpr ...

Adjust the height of the second column in Bootstrap 4 textarea to fill the remaining space

I am facing an issue with my layout where I have 2 columns, one containing some inputs and the other only a textarea. The problem is that I want the textarea in the second column to extend and fill the remaining height of the first column, but so far I hav ...

The issue with React Material UI MUI's 'MuiDialog-container' is that it persists on the screen even after the dialog has been closed, causing a blockage in the interface when the dialog is used

I have a dialog for employee search in my React app that I want to use in multiple places. For example, here is the component: import React, { useState, useEffect } from 'react'; import Button from '@mui/material/Button'; import Dialog ...

AngularJS field array

Is it possible to create an array that contains references to the fields in a form (such as input, textarea, etc.) and then run a function on them in my code, like addClass()? To clarify my objective - I am looking to add a red border color to any invalid ...

Canvg | Is there a way to customize canvas elements while converting from SVG?

Recently, I encountered an issue with styling SVG graphics dynamically generated from data. The SVG graphic appears like this: To address the problem, I turned to Canvg in hopes of converting the SVG into an image or PDF using a hidden canvas element. How ...

Difficulty encountered in aligning items within neighboring table cells vertically

Currently, I am facing a styling issue with a few table rows. In this particular screenshot: The cells in the blue and red circles are part of a table row (with a height of 50px). Both are set to "vertical-align:top". The phone number data (in the red cir ...

Retrieve information from an express server using the fetch API

I am attempting to use the alert function to display a variable string in Express's .get() method and then send it using res. I want the alert to show "I am working fetch". This is my server.js var express = require('express'); var app = e ...

ChooseRow on Material-UI Table

I'm diving into using MUI Datatables on a React project for the first time. I'm trying to figure out how to extract the data from the Row I select on the Checkbox. const options = { download: false, print: false, vie ...

I am looking to change the state of only the element that is being moused over in a React Hooks useState function, rather than changing the

Currently, I have a component from line 61-67 that controls the state of an editIcon. The issue is that it changes the state values for all items in the column, rather than just the specific item or row it should apply to. When hovering over a span element ...

What could be causing the issue with npm install packages not functioning properly?

Currently, I am in the process of setting up and deploying a particular git repository locally: https://github.com/maxie112/gatsby-ecommerce-theme I am strictly adhering to the instructions provided for Mac OS. Here are the encountered error logs; maxden ...

The MoralisProvider is malfunctioning due to a TypeError: The right-hand side of the 'instanceof' is not callable

The MoralisProvider component is not functioning as expected in a Next.js project import { MoralisProvider } from 'react-moralis' function MyApp({ Component, pageProps }) { return ( <MoralisProvider serverUrl={pro ...

Guide to resolving the issue of error Type 'void[] | undefined' cannot be assigned to type 'ReactNode'

I am attempting to map the data Array but I am encountering an error: Type 'void[] | undefined' is not assignable to type 'ReactNode'. Can someone please assist me in identifying what I am doing wrong here? Below is the code snippet: i ...

Enhance User Experience with a Responsive Website Dropdown Menu

Currently, I am focused on enhancing the responsiveness of my website and I realized that having a well-designed menu for mobile view is essential. To address this need, I added a button that only appears when the screen size is 480px or lower, which seems ...

Safari IOS experiencing issue with element disappearing unexpectedly when input is focused

I am facing a situation similar to the one discussed in the question (iOS 8.3 fixed HTML element disappears on input focus), but my problem differs slightly. My chatbox iframe is embedded within a scrollable parent, and when the iframe is activated, it exp ...

Communication failure between React and Node containers when attempting to dockerize app

I am currently in the process of dockerizing a react-node application. I have successfully created a docker compose file for this purpose. However, I am facing an issue where the react container fails to resolve the IP address of the node container when tr ...

Passing a data object dynamically through routing in Next.js

https://i.stack.imgur.com/e78s6.png I've encountered an issue while trying to pass an object to another route. My objective is to navigate to the edit page with the data of a specific row when the edit button is clicked. Passing just the id works fin ...

Utilizing an early release of Material-UI in a React web application with extensive content is essential when beta features are required for long-term success

When deciding whether to use a beta version of Material-UI for a long-term React web application with extensive content, consider if the beta features are necessary and if adhering to Google's Material Design Guidelines is essential. While alternativ ...