File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 11<script lang =" ts" >
2+ import { resize_textarea } from ' $lib/client/utils'
23 import { faCheckCircle , faWarning } from ' @fortawesome/free-solid-svg-icons'
34 import { tick } from ' svelte'
45 import Fa from ' svelte-fa'
6061
6162 <div class =" form-group" >
6263 <label for =" body" >Details</label >
63- <textarea id ="body" bind:value ={body } required ></textarea >
64+ <textarea id ="body" {@attach resize _textarea} bind:value ={body } required
65+ ></textarea >
6466 </div >
6567
6668 <button class ="button" disabled ={sending }>
Original file line number Diff line number Diff line change @@ -26,3 +26,21 @@ export function string_to_color(str: string): string {
2626 const h = hash % 360
2727 return `hsl(${ h } , 80%, 50%)`
2828}
29+
30+ export const resize_textarea : Attachment = ( textarea ) => {
31+ if ( ! ( textarea instanceof HTMLTextAreaElement ) ) return
32+
33+ textarea . style . height = `${ textarea . scrollHeight } px`
34+ textarea . style . overflowY = 'hidden'
35+
36+ const adjust = ( ) => {
37+ textarea . style . height = 'auto'
38+ textarea . style . height = `${ textarea . scrollHeight } px`
39+ }
40+
41+ textarea . addEventListener ( 'input' , adjust )
42+
43+ return ( ) => {
44+ textarea . removeEventListener ( 'input' , adjust )
45+ }
46+ }
You can’t perform that action at this time.
0 commit comments