diff --git a/routes/_utils/autosize.js b/routes/_utils/autosize.js index b29befb3..84880454 100644 --- a/routes/_utils/autosize.js +++ b/routes/_utils/autosize.js @@ -15,9 +15,18 @@ function assign (ta) { return } + let heightOffset = null let cachedHeight = null function init () { + const style = window.getComputedStyle(ta, null) + + if (style.boxSizing === 'content-box') { + heightOffset = -(parseFloat(style.paddingTop) + parseFloat(style.paddingBottom)) + } else { + heightOffset = parseFloat(style.borderTopWidth) + parseFloat(style.borderBottomWidth) + } + update() } @@ -33,7 +42,7 @@ function assign (ta) { ta.style.height = '' - let endHeight = ta.scrollHeight + let endHeight = ta.scrollHeight + heightOffset if (ta.scrollHeight === 0) { // If the scrollHeight is 0, then the element probably has display:none or is detached from the DOM.