diff --git a/src/autosize.js b/src/autosize.js index f69bb30..3f8de4d 100644 --- a/src/autosize.js +++ b/src/autosize.js @@ -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(); }