Skip to content

Commit

Permalink
feat(component): Auto-Expand Text area to content height
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-nfc committed Nov 13, 2024
1 parent 966645b commit a8b86c6
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/components/form/Textarea.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ const TextArea = ({
required={required}
className="common-field"
onChange={onChange}
onKeyUp={(e) =>{

const currentScrollY = window.scrollY

e.target.style.height = "1px";
e.target.style.height = ( 25 + e.target.scrollHeight ) + "px";

window.scrollTo(0, currentScrollY); // Prevent window scrolling to y=0

}}
onClick={(e) =>{

e.target.style.height = "1px";
e.target.style.height = ( 25 + e.target.scrollHeight ) + "px";

}}

>{value}</textarea>
<span className="error-text">{error_text}</span>
Expand Down

0 comments on commit a8b86c6

Please sign in to comment.