Skip to content

Commit

Permalink
Fixed minor bug where the resized event would not fire under specif…
Browse files Browse the repository at this point in the history
…ic conditions when changing the overflow.
  • Loading branch information
jackmoore committed Dec 4, 2016
1 parent 5c747b0 commit 6c198a8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Changelog

##### v.3.0.20 - 2016-12-04
* Fixed minor bug where the `resized` event would not fire under specific conditions when changing the overflow.

##### v.3.0.19 - 2016-11-23
* Bubble dispatched events. Merged #319.

Expand Down
20 changes: 11 additions & 9 deletions dist/autosize.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
Autosize 3.0.19
Autosize 3.0.20
license: MIT
http://www.jacklmoore.com/autosize
*/
Expand Down Expand Up @@ -103,8 +103,6 @@
}

ta.style.overflowY = value;

resize();
}

function getParentOverflows(el) {
Expand Down Expand Up @@ -156,25 +154,29 @@
function update() {
resize();

var computed = window.getComputedStyle(ta, null);
var computedHeight = Math.round(parseFloat(computed.height));
var styleHeight = Math.round(parseFloat(ta.style.height));
var computed = window.getComputedStyle(ta, null);
var actualHeight = Math.round(parseFloat(computed.height));

// The computed height not matching the height set via resize indicates that
// The actual height not matching the style height (set via the resize method) indicates that
// the max-height has been exceeded, in which case the overflow should be set to visible.
if (computedHeight !== styleHeight) {
if (actualHeight !== styleHeight) {
if (computed.overflowY !== 'visible') {
changeOverflow('visible');
resize();
actualHeight = Math.round(parseFloat(window.getComputedStyle(ta, null).height));
}
} else {
// Normally keep overflow set to hidden, to avoid flash of scrollbar as the textarea expands.
if (computed.overflowY !== 'hidden') {
changeOverflow('hidden');
resize();
actualHeight = Math.round(parseFloat(window.getComputedStyle(ta, null).height));
}
}

if (cachedHeight !== computedHeight) {
cachedHeight = computedHeight;
if (cachedHeight !== actualHeight) {
cachedHeight = actualHeight;
var evt = createEvent('autosize:resized');
try {
ta.dispatchEvent(evt);
Expand Down
4 changes: 2 additions & 2 deletions dist/autosize.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "autosize",
"description": "Autosize is a small, stand-alone script to automatically adjust textarea height to fit text.",
"version": "3.0.19",
"version": "3.0.20",
"keywords": [
"textarea",
"form",
Expand Down
18 changes: 10 additions & 8 deletions src/autosize.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ function assign(ta) {
}

ta.style.overflowY = value;

resize();
}

function getParentOverflows(el) {
Expand Down Expand Up @@ -134,25 +132,29 @@ function assign(ta) {
function update() {
resize();

const computed = window.getComputedStyle(ta, null);
const computedHeight = Math.round(parseFloat(computed.height));
const styleHeight = Math.round(parseFloat(ta.style.height));
const computed = window.getComputedStyle(ta, null);
var actualHeight = Math.round(parseFloat(computed.height));

// The computed height not matching the height set via resize indicates that
// The actual height not matching the style height (set via the resize method) indicates that
// the max-height has been exceeded, in which case the overflow should be set to visible.
if (computedHeight !== styleHeight) {
if (actualHeight !== styleHeight) {
if (computed.overflowY !== 'visible') {
changeOverflow('visible');
resize();
actualHeight = Math.round(parseFloat(window.getComputedStyle(ta, null).height));
}
} else {
// Normally keep overflow set to hidden, to avoid flash of scrollbar as the textarea expands.
if (computed.overflowY !== 'hidden') {
changeOverflow('hidden');
resize();
actualHeight = Math.round(parseFloat(window.getComputedStyle(ta, null).height));
}
}

if (cachedHeight !== computedHeight) {
cachedHeight = computedHeight;
if (cachedHeight !== actualHeight) {
cachedHeight = actualHeight;
const evt = createEvent('autosize:resized');
try {
ta.dispatchEvent(evt);
Expand Down

0 comments on commit 6c198a8

Please sign in to comment.