diff options
author | Jack Moore <hello@jacklmoore.com> | 2016-07-25 19:16:37 -0400 |
---|---|---|
committer | Jack Moore <hello@jacklmoore.com> | 2016-07-25 19:16:37 -0400 |
commit | 5edede50943083a0a3d0781ba3c7494b8691dfcd (patch) | |
tree | 7a806a8b4fc88abaa9107c10fa77f44043584733 | |
parent | adf29738521cbedae7e2c4fc98e231363728c0c1 (diff) | |
download | autosize-5edede50943083a0a3d0781ba3c7494b8691dfcd.zip autosize-5edede50943083a0a3d0781ba3c7494b8691dfcd.tar.gz autosize-5edede50943083a0a3d0781ba3c7494b8691dfcd.tar.bz2 |
worked around Chromium issue where getComputedStyle pixel value did not exactly match the style pixel value. Fixes #306.
-rw-r--r-- | src/autosize.js | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/autosize.js b/src/autosize.js index 37343e7..42fb2bc 100644 --- a/src/autosize.js +++ b/src/autosize.js @@ -31,6 +31,7 @@ function assign(ta) { let heightOffset = null; let clientWidth = ta.clientWidth; + let cachedHeight = null; function init() { const style = window.getComputedStyle(ta, null); @@ -120,26 +121,27 @@ function assign(ta) { } function update() { - const startHeight = ta.style.height; - resize(); - const style = window.getComputedStyle(ta, null); + const computed = window.getComputedStyle(ta, null); + const computedHeight = Math.round(parseFloat(computed.height)); + const styleHeight = Math.round(parseFloat(ta.style.height)); // The computed height not matching the height set via resize indicates that // the max-height has been exceeded, in which case the overflow should be set to visible. - if (style.height !== ta.style.height) { - if (style.overflowY !== 'visible') { + if (computedHeight !== styleHeight) { + if (computed.overflowY !== 'visible') { changeOverflow('visible'); } } else { // Normally keep overflow set to hidden, to avoid flash of scrollbar as the textarea expands. - if (style.overflowY !== 'hidden') { + if (computed.overflowY !== 'hidden') { changeOverflow('hidden'); } } - if (startHeight !== ta.style.height) { + if (cachedHeight !== computedHeight) { + cachedHeight = computedHeight; const evt = createEvent('autosize:resized'); ta.dispatchEvent(evt); } |