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

239
Vistas
Material UI TextField, format mandatory fields

I want to change the underline border color of the TextFields which are mandatory in a form (react-hooks-form).

I suppose I need to create a style for these, but here is where I got stuck...

This is my code:

field:

               <Controller
                  name="date"
                  control={control}
                  defaultValue={props.operation === 'edit' ? props.values.date : null}
                  render={({ field: { onChange, value }, fieldState: { error } }) => (
                    <TextField
                      id="date"
                      type="date"
                      label="date"
                      
                      value={value}
                      className={classes.textField}
                      onChange={(event) => {
                        onChange(event.target.value);
                        setValue('week', getWeek(event.target.value))
                      }}
                      error={!!error}
                      helperText={error ? error.message : null}
                      InputLabelProps={{
                        shrink: true,
                      }}
                      ///added
                      InputProps={{
                        className: classes.mandatory,
                      }}
                    />
                  )}
                  rules={{ required: 'Date is required' }}
                />

styles:

const useStyles = makeStyles((theme: Theme) =>
  createStyles({
    root: {
      '& .MuiTextField-root': {
        margin: theme.spacing(2),
        width: '26ch',
      },
    },
   ///added
    mandatory: {
      borderBottom: '1px solid rgb(215 50 50 / 70%)'
    }
  }),
);

I have tried to add the border color, but it doesn't work.

The only solution I found until now is to make the filed focused...

UPDATE #2: possible solution add style to TextField:

 <TextField
                          {...params }
                          error={!!error}
                          helperText={error ? error.message : null}
                          label="appel*"
                          className={`mandatory ${classes.textField}`}
                          style={{ borderBottom: '1px solid red' }}
                        />
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

if you just want to change the border-color of textFied border :

   "& .css-h5voop-MuiInputBase-root-MuiInput-root:before": {
        borderBottom:" 1px solid rgb(215 50 50 / 70%)",
            },

or in textField :

 <TextField variant="standard"  required label="Ship Name" name="name"
 
                                   InputProps={{
                                       disableUnderline:true,
                                       sx:{
                                           borderBottom:"2px solid green",
                                       }
                                   }}
                        />
about 4 years ago · Juan Pablo Isaza Denunciar

0

Could you try, please

<Controller
                  name="date"
                  control={control}
                  defaultValue={props.operation === 'edit' ? props.values.date : null}
                  render={({ field: { onChange, value }, fieldState: { error } }) => (
                    <TextField
                      id="date"
                      type="date"
                      label="date"
                      
                      value={value}
                      className={`mandatory ${classes.textField}`}
                      onChange={(event) => {
                        onChange(event.target.value);
                        setValue('week', getWeek(event.target.value))
                      }}
                      error={!!error}
                      helperText={error ? error.message : null}
                      InputLabelProps={{
                        shrink: true,
                      }}
                    />
                  )}
                  rules={{ required: 'Date is required' }}
                />

then add style

.mandatory fieldset[aria-hidden="true"] {
      borderBottom: '1px solid rgb(215 50 50 / 70%)'
    }
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