diff options
author | Allan Wang <me@allanwang.ca> | 2020-05-23 19:34:00 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2020-05-23 19:34:00 -0700 |
commit | 28c105cb0cc9593930f069584662380a7674c249 (patch) | |
tree | 2a340e398beb7b4e5888c49fcbc0f5f7ba88862b /app/src/web | |
parent | 7c8e02d385d418ebae1f8f718b72c4170a1bc819 (diff) | |
download | frost-28c105cb0cc9593930f069584662380a7674c249.tar.gz frost-28c105cb0cc9593930f069584662380a7674c249.tar.bz2 frost-28c105cb0cc9593930f069584662380a7674c249.zip |
Add auto resize to text areas
Diffstat (limited to 'app/src/web')
-rw-r--r-- | app/src/web/ts/auto_resize_textarea.ts | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/app/src/web/ts/auto_resize_textarea.ts b/app/src/web/ts/auto_resize_textarea.ts new file mode 100644 index 00000000..f690d4c0 --- /dev/null +++ b/app/src/web/ts/auto_resize_textarea.ts @@ -0,0 +1,22 @@ +// Credits to https://codepen.io/tomhodgins/pen/KgazaE +(function () { + const textareas = <NodeListOf<HTMLTextAreaElement>>document.querySelectorAll('textarea.frostAutoExpand'); + + const _frostAutoExpand = (el: HTMLElement) => { + el.style.height = 'inherit' + el.style.height = `${el.scrollHeight}px` + }; + function _frostExpandAll() { + textareas.forEach(_frostAutoExpand); + } + textareas.forEach(el => { + const __frostAutoExpand = () => { + _frostAutoExpand(el) + }; + el.addEventListener('paste', __frostAutoExpand) + el.addEventListener('input', __frostAutoExpand) + el.addEventListener('keyup', __frostAutoExpand) + }); + window.addEventListener('load', _frostExpandAll) + window.addEventListener('resize', _frostExpandAll) +}).call(undefined); |