Skip to content

Commit

Permalink
worked around Chromium issue where getComputedStyle pixel value did n…
Browse files Browse the repository at this point in the history
…ot exactly match the style pixel value. Fixes jackmoore#306.
  • Loading branch information
jackmoore committed Jul 25, 2016
1 parent adf2973 commit 5edede5
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/autosize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 5edede5

Please sign in to comment.