react-textarea-autosize
Advanced tools
Comparing version 2.1.3 to 2.2.0
@@ -21,2 +21,3 @@ 'use strict'; | ||
var minRows = arguments[2] === undefined ? null : arguments[2]; | ||
var maxRows = arguments[3] === undefined ? null : arguments[3]; | ||
@@ -41,13 +42,31 @@ if (!hiddenTextarea) { | ||
if (minRows !== null) { | ||
hiddenTextarea.value = uiTextNode.value; | ||
var height = hiddenTextarea.scrollHeight - sumVerticalPaddings; | ||
if (minRows !== null || maxRows !== null) { | ||
// measure height of a textarea with a single row | ||
hiddenTextarea.value = 'x'; | ||
var singleRowHeight = hiddenTextarea.scrollHeight - sumVerticalPaddings; | ||
hiddenTextarea.value = uiTextNode.value; | ||
var height = hiddenTextarea.scrollHeight - sumVerticalPaddings; | ||
return Math.max(singleRowHeight * minRows, height); | ||
} else { | ||
hiddenTextarea.value = uiTextNode.value; | ||
return hiddenTextarea.scrollHeight - sumVerticalPaddings; | ||
if (minRows !== null) { | ||
var minHeight = singleRowHeight * minRows; | ||
return { | ||
height: Math.max(minHeight, height), | ||
minHeight: minHeight, | ||
maxHeight: Infinity | ||
}; | ||
} | ||
if (maxRows !== null) { | ||
var maxHeight = singleRowHeight * maxRows; | ||
return { | ||
height: Math.min(maxHeight, height), | ||
minHeight: -Infinity, | ||
maxHeight: maxHeight | ||
}; | ||
} | ||
} | ||
return { | ||
height: height, | ||
minHeight: -Infinity, | ||
maxHeight: Infinity | ||
}; | ||
} | ||
@@ -54,0 +73,0 @@ |
@@ -41,3 +41,7 @@ 'use strict'; | ||
_get(Object.getPrototypeOf(TextareaAutosize.prototype), 'constructor', this).call(this, props); | ||
this.state = { height: null }; | ||
this.state = { | ||
height: null, | ||
minHeight: -Infinity, | ||
maxHeight: Infinity | ||
}; | ||
this._onChange = this._onChange.bind(this); | ||
@@ -65,3 +69,4 @@ this._resizeComponent = this._resizeComponent.bind(this); | ||
}); | ||
if (!props.style.maxHeight || props.style.maxHeight > props.style.height) { | ||
var maxHeight = Math.max(props.style.maxHeight ? props.style.maxHeight : Infinity, this.state.maxHeight); | ||
if (maxHeight < this.state.height) { | ||
props.style.overflow = 'hidden'; | ||
@@ -101,4 +106,3 @@ } | ||
var height = _calculateNodeHeight2['default'](_React2['default'].findDOMNode(this), useCacheForDOMMeasurements, this.props.rows); | ||
this.setState({ height: height }); | ||
this.setState(_calculateNodeHeight2['default'](_React2['default'].findDOMNode(this), useCacheForDOMMeasurements, this.props.rows || this.props.minRows, this.props.maxRows)); | ||
} | ||
@@ -143,3 +147,18 @@ }, { | ||
*/ | ||
useCacheForDOMMeasurements: _React2['default'].PropTypes.bool | ||
useCacheForDOMMeasurements: _React2['default'].PropTypes.bool, | ||
/** | ||
* Minimal numbder of rows to show. | ||
*/ | ||
rows: _React2['default'].PropTypes.number, | ||
/** | ||
* Alias for `rows`. | ||
*/ | ||
minRows: _React2['default'].PropTypes.number, | ||
/** | ||
* Maximum number of rows to show. | ||
*/ | ||
maxRows: _React2['default'].PropTypes.number | ||
}, | ||
@@ -146,0 +165,0 @@ enumerable: true |
{ | ||
"name": "react-textarea-autosize", | ||
"description": "textarea component for React which grows with content", | ||
"version": "2.1.3", | ||
"version": "2.2.0", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Andrey Popp", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26899
237