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

163
Vistas
Change css of relative element based on change or click in reactjs

I have created a form with custom styled input component in react material ui,it goes something like this

onst StyledInputElement = styled('input')(`
  width: 200px;
  font-size: 1rem;
  font-family: IBM Plex Sans, sans-serif;
  font-weight: 400;
  line-height: 1.4375em;
  background: rgb(243, 246, 249);
  border: 1px solid #E5E8EC;
  border-radius: 10px;
  padding: 6px 10px;
  color: #20262D;
  transition: width 300ms ease;

  &:hover {
    background: #EAEEF3;
    border-color: #E5E8EC;
  }

  &:focus {
    outline: none;
    width: 320px;
    transition: width 200ms ease-out;
  }
`);

const CustomInput = React.forwardRef(function CustomInput(props, ref) {
  return (
    <InputUnstyled components={{ Input: StyledInputElement }} {...props} ref={ref} />
  );
});


const AuthDialog = (props) => {

  return (
    <>
      <CssBaseline />
      <Dialog
        fullWidthS
        onClose={() => {}}
        open={props.dilaogOpenProp}
        maxWidth="xs"
        sx={{
          backdropFilter: "blur(3px)",
        }}
      >
        <DialogTitle>Please login</DialogTitle>
        <DialogContent>
        <CustomInput aria-label="Demo input" placeholder="Username" />
        <br/>
        <CustomInput onClick aria-label="Demo input" placeholder="Password" />
        </DialogContent>
        <DialogActions>
          <Button onClick={props.handleDialogCloseProp}>Close</Button>
        </DialogActions>
      </Dialog>
      <Box
        sx={{
          minHeight: "100vh",
          background:
            "url(https://source.unsplash.com/random) no-repeat center center",
          backgroundSize: "cover",
        }}
      ></Box>
    </>
  );
}

export default AuthDialog;

Now it works something like this

Before click

enter image description here

As you can see on clicking one of the text fields is expanding but that leaves another text field to its same size, how do I apply text field expands CSS on both of the text fields even if I click any one of them?

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

0

You can use :focus-within on the parent of the two inputs.

const StyledContainer = styled('div')(`
   &:focus-within input {
     outline: none;
     width: 320px;
     transition: width 200ms ease-out;
   }
`)

Then surround your two inputs with this container:

<StyledContainer>
  <CustomInput aria-label="Demo input" placeholder="Username" />
  <br/>
  <CustomInput onClick aria-label="Demo input" placeholder="Password" />
</StyledContainer>

(Note: not supported by IE11)

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