Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

142
Vistas
Styling order of Material UI

I've spent like 10 hours on customization to understand it perfectly but it makes me headache as I go on.

I'm styling outlined TextField, specifically its label and border. I thought it wouldn't be problematic if I use sx prop to customize but it didn't work well as I had expected.

const One = () => (
  <div>
    <TextField
      id="outlined-basic"
      label="One"
      variant="outlined"
      sx={{
        "& .MuiOutlinedInput-root": {
          borderRadius: 0
        },

        "& .MuiInputLabel-root": {
          color: "orange"
        },

        "& .Mui-focused .MuiOutlinedInput-notchedOutline": {
          borderColor: "orange"
        }
      }}
    />
  </div>

I want label to be orange always, and border to be orange when focused. But when I focus on the TextField, label and border go back to blue. But border-radius works well.

I inspected the result and it seemed like default style was inserted again when the component was focused. I don't get it because I think it should have been inserted earlier, like when the TextField mounted. Why is sx prop not overriding the default style?

enter image description here

https://codesandbox.io/s/material-ui-customization-zg5v5v?file=/src/components/One.jsx

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can increase the specificity of the focused class selector by adding it to the root.

const One = () => (
  <div>
    <TextField
      id="outlined-basic"
      label="One"
      variant="outlined"
      sx={{
        '& .MuiOutlinedInput-root': {
          borderRadius: 0,
        },

        '& .MuiInputLabel-root': {
          color: 'orange',
        },

        '&  .MuiOutlinedInput-root.Mui-focused .MuiOutlinedInput-notchedOutline': {
          borderColor: 'orange',
        },
      }}
    />
  </div>
);

This oughta do it for ya!

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can nest your last style in your first style

Here is a sandbox

<TextField
  id="outlined-basic"
  label="One"
  variant="outlined"
  sx={{
    "& .MuiOutlinedInput-root": {
      borderRadius: 0,
      "&.Mui-focused .MuiOutlinedInput-notchedOutline": {
        borderColor: "orange",
        color: "inherit"
      }
    },

    "& .MuiInputLabel-root": {
      color: "orange"
    }
  }}
/>;
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda