Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

352
Views
Cómo hacer que el área de texto se expanda cuando hay algún valor

Estoy tratando de hacer que el área de texto se expanda cuando ingreso algo de texto en él, estoy usando focus css para que se expanda, pero cuando hago clic fuera del área de texto, volverá a su valor predeterminado.

Aquí está mi base de código:

 <DynamicWidthInput id="addLoanClause" value={addLoanClause} type="textarea" placeholder="" error={showErrors && getError("addLoanClause")} onChange={e => handleDynamicStateChange(e, setAddLoanClause) } size={"xl"} rows="5" />

y aquí está mi estilo.css:

 .dynamic-textarea { text-align: left; transition: all .3s ease; height: 60px; } .dynamic-textarea:focus { height: 150px; width: 650px !important; }

¿Cómo puedo lograr la función cuando hay texto en el área de texto que se expandirá automáticamente? estoy usando reaccionar

Componente actualizado y agregado DynamicWidthInput.js:

 class DynamicWidthInput extends React.Component { componentDidMount() { const { id, value } = this.props; resizable(document.getElementById(id), 16, value); } componentDidUpdate(prevProps) { const { id, value } = this.props; if (this.props.value !== prevProps.value) { resizable(document.getElementById(id), 16, value); } } render() { const { id, placeholder, type, onChange, value, error, size } = this.props; if (type === "textarea") { return ( <div style={{ display: "inline-block", verticalAlign: "top" }}> <textarea className={`input dynamic-input dynamic-textarea ${size}`} id={id} onChange={onChange} placeholder={placeholder} value={value} wrap="soft" maxLength="1000" {...this.props} /> {error && <p className="help is-danger">{error.message}</p>} </div> ); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede cambiar dinámicamente el atributo de rows en el área de texto cuando ocurre un cambio.

Aquí hay un Codepen con un ejemplo: https://codepen.io/JaKto/pen/qeBpZM

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!