Skip to content

Commit

Permalink
Add the function to init element height
Browse files Browse the repository at this point in the history
  • Loading branch information
rayc2045 committed Jun 7, 2024
1 parent 5dafdcd commit b5d3410
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ const utils = {
el.removeAttribute('style');
for (const prop in style) el.style[prop] = style[prop];
},
initHeight(el) {
el.removeAttribute('style');
el.style.height = el.scrollHeight + 'px';
},
getUniques(arr) {
return arr.filter((item, idx) => arr.indexOf(item) === idx);
},
Expand Down
2 changes: 1 addition & 1 deletion src/pages/about/contact.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h2 class="text-2xl font-bold">Get in touch</h2>
rows="4"
placeholder="Leave a message..."
x-ref="textarea"
@input="$el.removeAttribute('style'); $el.style.height = `${$el.scrollHeight}px`; $el.value = $el.value.replaceAll(' ', ' ').replaceAll('\n\n\n', '\n\n');"
@input="initHeight($el); $el.value = $el.value.replaceAll(' ', ' ').replaceAll('\n\n\n', '\n\n');"
></textarea>
<div class="p-3 flex items-center justify-end gap-2">
<button
Expand Down

0 comments on commit b5d3410

Please sign in to comment.