From ae7b96abbf0c027f0f746ca8f83d06b7ecf2d925 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Wed, 19 Dec 2018 01:11:57 +0300 Subject: [PATCH 1/4] Fix resize not working properly for textareas --- .../post_status_form/post_status_form.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/components/post_status_form/post_status_form.js b/src/components/post_status_form/post_status_form.js index 0ce2aff0..fa994c87 100644 --- a/src/components/post_status_form/post_status_form.js +++ b/src/components/post_status_form/post_status_form.js @@ -246,7 +246,7 @@ const PostStatusForm = { } this.$emit('posted') let el = this.$el.querySelector('textarea') - el.style.height = '16px' + el.style.height = undefined this.error = null } else { this.error = data.error @@ -294,13 +294,15 @@ const PostStatusForm = { e.dataTransfer.dropEffect = 'copy' }, resize (e) { - if (!e.target) { return } - const vertPadding = Number(window.getComputedStyle(e.target)['padding-top'].substr(0, 1)) + - Number(window.getComputedStyle(e.target)['padding-bottom'].substr(0, 1)) - e.target.style.height = 'auto' - e.target.style.height = `${e.target.scrollHeight - vertPadding}px` - if (e.target.value === '') { - e.target.style.height = '16px' + const target = e.target || e + if (!(target instanceof window.Element)) { return } + const vertPadding = Number(window.getComputedStyle(target)['padding-top'].substr(0, 1)) + + Number(window.getComputedStyle(target)['padding-bottom'].substr(0, 1)) + // Auto is needed to make textbox shrink when removing lines + target.style.height = 'auto' + target.style.height = `${target.scrollHeight - vertPadding}px` + if (target.value === '') { + target.style.height = undefined } }, clearError () { From afa2baec0cc57fd0beb3aac26048717569d5b116 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Wed, 19 Dec 2018 01:23:52 +0300 Subject: [PATCH 2/4] I suppose SOME browsers don't do this by default... --- src/components/post_status_form/post_status_form.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/post_status_form/post_status_form.js b/src/components/post_status_form/post_status_form.js index fa994c87..46dcc8a6 100644 --- a/src/components/post_status_form/post_status_form.js +++ b/src/components/post_status_form/post_status_form.js @@ -32,6 +32,8 @@ const PostStatusForm = { }, mounted () { this.resize(this.$refs.textarea) + const textLength = this.$refs.textarea.value.length + this.$refs.textarea.setSelectionRange(textLength, textLength) if (this.replyTo) { this.$refs.textarea.focus() From 5970bf4e856b6ced0bbbf53268411f95ce3e1341 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Thu, 20 Dec 2018 07:27:29 +0300 Subject: [PATCH 3/4] fixed incorrect height when empty text --- src/components/post_status_form/post_status_form.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/post_status_form/post_status_form.js b/src/components/post_status_form/post_status_form.js index 46dcc8a6..94c75b6a 100644 --- a/src/components/post_status_form/post_status_form.js +++ b/src/components/post_status_form/post_status_form.js @@ -304,7 +304,7 @@ const PostStatusForm = { target.style.height = 'auto' target.style.height = `${target.scrollHeight - vertPadding}px` if (target.value === '') { - target.style.height = undefined + target.style.height = null } }, clearError () { From 18d7684f3243da4068dcc21b66854484fb61b062 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Tue, 25 Dec 2018 04:24:49 +0300 Subject: [PATCH 4/4] fix for non-shrinking main post form --- src/components/post_status_form/post_status_form.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/post_status_form/post_status_form.js b/src/components/post_status_form/post_status_form.js index 94c75b6a..2435074b 100644 --- a/src/components/post_status_form/post_status_form.js +++ b/src/components/post_status_form/post_status_form.js @@ -248,6 +248,7 @@ const PostStatusForm = { } this.$emit('posted') let el = this.$el.querySelector('textarea') + el.style.height = 'auto' el.style.height = undefined this.error = null } else {