Skip to content
This repository has been archived by the owner on Jul 21, 2021. It is now read-only.

Commit

Permalink
Disable autosizing when textarea is manually resized
Browse files Browse the repository at this point in the history
There's no great way to currently test for this with js, so fall back to
using mouse events and detecting a change when the mouse is down.
  • Loading branch information
wlach committed Jul 17, 2017
1 parent a33fcfe commit 6d12995
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/autosize.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,32 @@ function assign(ta) {
heightOffset = 0;
}

var mouseDownListener = () => {
// suspend maximum height so that user can resize to greater
// than it
var oldMaxHeight = ta.style['max-height'];
ta.style.height = ta.offsetHeight + 'px';
ta.style['max-height'] = null;

var heightBefore = ta.clientHeight;
var mouseMoveListener = () => {
var heightAfter = ta.clientHeight;
if (heightAfter !== heightBefore) {
oldMaxHeight = null;
ta.removeEventListener('mousemove', mouseMoveListener);
ta.removeEventListener('mousedown', mouseDownListener);
destroy(ta);
}
};
ta.addEventListener('mousemove', mouseMoveListener);
ta.addEventListener('mouseup', () => {
ta.style['max-height'] = oldMaxHeight;
ta.removeEventListener('mouseup', this);
ta.removeEventListener('mousemove', mouseMoveListener);
});
};
ta.addEventListener('mousedown', mouseDownListener);

update();
}

Expand Down

0 comments on commit 6d12995

Please sign in to comment.