Fix resize not working properly for textareas

This commit is contained in:
Henry Jameson 2018-12-19 01:11:57 +03:00
parent f62ff2d894
commit ae7b96abbf

View file

@ -246,7 +246,7 @@ const PostStatusForm = {
} }
this.$emit('posted') this.$emit('posted')
let el = this.$el.querySelector('textarea') let el = this.$el.querySelector('textarea')
el.style.height = '16px' el.style.height = undefined
this.error = null this.error = null
} else { } else {
this.error = data.error this.error = data.error
@ -294,13 +294,15 @@ const PostStatusForm = {
e.dataTransfer.dropEffect = 'copy' e.dataTransfer.dropEffect = 'copy'
}, },
resize (e) { resize (e) {
if (!e.target) { return } const target = e.target || e
const vertPadding = Number(window.getComputedStyle(e.target)['padding-top'].substr(0, 1)) + if (!(target instanceof window.Element)) { return }
Number(window.getComputedStyle(e.target)['padding-bottom'].substr(0, 1)) const vertPadding = Number(window.getComputedStyle(target)['padding-top'].substr(0, 1)) +
e.target.style.height = 'auto' Number(window.getComputedStyle(target)['padding-bottom'].substr(0, 1))
e.target.style.height = `${e.target.scrollHeight - vertPadding}px` // Auto is needed to make textbox shrink when removing lines
if (e.target.value === '') { target.style.height = 'auto'
e.target.style.height = '16px' target.style.height = `${target.scrollHeight - vertPadding}px`
if (target.value === '') {
target.style.height = undefined
} }
}, },
clearError () { clearError () {