aboutsummaryrefslogtreecommitdiff
path: root/app/src/web/ts
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2020-10-03 21:27:10 -0700
committerAllan Wang <me@allanwang.ca>2020-10-03 21:27:10 -0700
commit6af10978aa5a4aaf1f596c54c4c5ef3373bec905 (patch)
treef0e323f99ae15fd45f33cdf43476f99ad5da18ab /app/src/web/ts
parentad9fdf9f6718918e9daf5c0afb378f0bc4e47283 (diff)
downloadfrost-6af10978aa5a4aaf1f596c54c4c5ef3373bec905.tar.gz
frost-6af10978aa5a4aaf1f596c54c4c5ef3373bec905.tar.bz2
frost-6af10978aa5a4aaf1f596c54c4c5ef3373bec905.zip
Add back scroll position after height change
Diffstat (limited to 'app/src/web/ts')
-rw-r--r--app/src/web/ts/auto_resize_textarea.ts11
1 files changed, 11 insertions, 0 deletions
diff --git a/app/src/web/ts/auto_resize_textarea.ts b/app/src/web/ts/auto_resize_textarea.ts
index 1f1b3613..c71a75a1 100644
--- a/app/src/web/ts/auto_resize_textarea.ts
+++ b/app/src/web/ts/auto_resize_textarea.ts
@@ -12,8 +12,19 @@
// If no height is defined, have min bound to current height;
// otherwise we will allow for height decreases in case user deletes text
const minHeight = parseInt(el.getAttribute(dataAttribute) ?? '0');
+
+ // Save scroll position prior to height update
+ // See https://stackoverflow.com/a/18262927/4407321
+ const scrollLeft = window.pageXOffset ||
+ (document.documentElement || document.body.parentNode || document.body).scrollLeft;
+ const scrollTop = window.pageYOffset ||
+ (document.documentElement || document.body.parentNode || document.body).scrollTop;
+
el.style.height = 'inherit';
el.style.height = `${Math.max(el.scrollHeight, minHeight)}px`;
+
+ // Go to original scroll position
+ window.scrollTo(scrollLeft, scrollTop);
};
function _frostExpandAll() {
textareas.forEach(_frostAutoExpand);