Skip to content

Commit

Permalink
Avoided adjusting the height for hidden textarea elements. Fixes jack…
Browse files Browse the repository at this point in the history
  • Loading branch information
jackmoore committed Apr 23, 2015
1 parent 85ccb80 commit 8c438c7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 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.3 - 2015-04-23
* Avoided adjusting the height for hidden textarea elements. Fixes #155.

##### v.3.0.2 - 2015-04-23
* Reworked to respect max-height of any unit-type. Fixes #191.

Expand Down
7 changes: 7 additions & 0 deletions dest/autosize.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,18 @@
var startHeight = ta.style.height;
var htmlTop = document.documentElement.scrollTop;
var bodyTop = document.body.scrollTop;
var originalHeight = ta.style.height;

ta.style.height = 'auto';

var 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.
ta.style.height = originalHeight;
return;
}

ta.style.height = endHeight + 'px';

// prevents scroll-position jumping
Expand Down
2 changes: 1 addition & 1 deletion dest/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.2",
"version": "3.0.3",
"keywords": [
"textarea",
"form",
Expand Down
9 changes: 8 additions & 1 deletion src/autosize.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,18 @@ function assign(ta) {
const startHeight = ta.style.height;
const htmlTop = document.documentElement.scrollTop;
const bodyTop = document.body.scrollTop;

const originalHeight = ta.style.height;

ta.style.height = 'auto';

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.
ta.style.height = originalHeight;
return;
}

ta.style.height = endHeight+'px';

// prevents scroll-position jumping
Expand Down

0 comments on commit 8c438c7

Please sign in to comment.