From cef354d41271e0935fe1adb068d11ef82bf76316 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sun, 25 Feb 2018 23:01:15 -0800 Subject: [PATCH] fix box sizing calculations --- routes/_utils/autosize.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/routes/_utils/autosize.js b/routes/_utils/autosize.js index b29befb..8488045 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.