react-textarea-autosize
Advanced tools
Comparing version 2.4.1 to 2.4.2
@@ -33,4 +33,6 @@ 'use strict'; | ||
var paddingSize = _calculateNodeStyling.paddingSize; | ||
var borderSize = _calculateNodeStyling.borderSize; | ||
var boxSizing = _calculateNodeStyling.boxSizing; | ||
var sizingStyle = _calculateNodeStyling.sizingStyle; | ||
var heightAdjustment = _calculateNodeStyling.heightAdjustment; | ||
@@ -41,14 +43,25 @@ // Need to have the overflow attribute to hide the scrollbar otherwise | ||
hiddenTextarea.setAttribute('style', sizingStyle + ';' + HIDDEN_TEXTAREA_STYLE); | ||
hiddenTextarea.value = uiTextNode.value; | ||
hiddenTextarea.value = uiTextNode.value; | ||
var height = hiddenTextarea.scrollHeight + heightAdjustment; | ||
var minHeight = -Infinity; | ||
var maxHeight = Infinity; | ||
var height = hiddenTextarea.scrollHeight; | ||
if (boxSizing === 'border-box') { | ||
// border-box: add border, since height = content + padding + border | ||
height = height + borderSize; | ||
} else if (boxSizing === 'content-box') { | ||
// remove padding, since height = content | ||
height = height - paddingSize; | ||
} | ||
if (minRows !== null || maxRows !== null) { | ||
// measure height of a textarea with a single row | ||
hiddenTextarea.value = 'x'; | ||
var singleRowHeight = hiddenTextarea.scrollHeight + heightAdjustment; | ||
var singleRowHeight = hiddenTextarea.scrollHeight - paddingSize; | ||
if (minRows !== null) { | ||
minHeight = singleRowHeight * minRows; | ||
if (boxSizing === 'border-box') { | ||
minHeight = minHeight + paddingSize + borderSize; | ||
} | ||
height = Math.max(minHeight, height); | ||
@@ -58,2 +71,5 @@ } | ||
maxHeight = singleRowHeight * maxRows; | ||
if (boxSizing === 'border-box') { | ||
maxHeight = maxHeight + paddingSize + borderSize; | ||
} | ||
height = Math.min(maxHeight, height); | ||
@@ -74,22 +90,19 @@ } | ||
var compStyle = window.getComputedStyle(node); | ||
var style = window.getComputedStyle(node); | ||
// scrollHeight = content + padding; depending on what box-sizing is | ||
// set to, we'll need an adjustment when we set the new height | ||
var heightAdjustment = 0; | ||
var boxSizing = style.getPropertyValue('box-sizing') || style.getPropertyValue('-moz-box-sizing') || style.getPropertyValue('-webkit-box-sizing'); | ||
var boxSizing = compStyle.getPropertyValue('box-sizing') || compStyle.getPropertyValue('-moz-box-sizing') || compStyle.getPropertyValue('-webkit-box-sizing'); | ||
// border-box: add border, since height = content + padding + border | ||
if (boxSizing === 'border-box') { | ||
heightAdjustment = parseFloat(compStyle.getPropertyValue('border-bottom-width')) + parseFloat(compStyle.getPropertyValue('border-top-width')); | ||
} else if (boxSizing === 'content-box') { | ||
// remove padding, since height = content | ||
heightAdjustment = -(parseFloat(compStyle.getPropertyValue('padding-bottom')) + parseFloat(compStyle.getPropertyValue('padding-top'))); | ||
} | ||
var paddingSize = parseFloat(style.getPropertyValue('padding-bottom')) + parseFloat(style.getPropertyValue('padding-top')); | ||
var borderSize = parseFloat(style.getPropertyValue('border-bottom-width')) + parseFloat(style.getPropertyValue('border-top-width')); | ||
var sizingStyle = SIZING_STYLE.map(function (name) { | ||
return '' + name + ':' + style.getPropertyValue(name); | ||
}).join(';'); | ||
var nodeInfo = { | ||
sizingStyle: SIZING_STYLE.map(function (name) { | ||
return '' + name + ':' + compStyle.getPropertyValue(name); | ||
}).join(';'), | ||
heightAdjustment: heightAdjustment | ||
sizingStyle: sizingStyle, | ||
paddingSize: paddingSize, | ||
borderSize: borderSize, | ||
boxSizing: boxSizing | ||
}; | ||
@@ -100,4 +113,5 @@ | ||
} | ||
return nodeInfo; | ||
} | ||
module.exports = exports['default']; |
{ | ||
"name": "react-textarea-autosize", | ||
"description": "textarea component for React which grows with content", | ||
"version": "2.4.1", | ||
"version": "2.4.2", | ||
"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
28496
276