|
|
|
@ -5,15 +5,15 @@
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
const HIDDEN_TEXTAREA_STYLE = `
|
|
|
|
|
min-height:0 !important;
|
|
|
|
|
max-height:none !important;
|
|
|
|
|
height:0 !important;
|
|
|
|
|
visibility:hidden !important;
|
|
|
|
|
overflow:hidden !important;
|
|
|
|
|
position:absolute !important;
|
|
|
|
|
z-index:-1000 !important;
|
|
|
|
|
top:0 !important;
|
|
|
|
|
right:0 !important
|
|
|
|
|
min-height:0 !important;
|
|
|
|
|
max-height:none !important;
|
|
|
|
|
height:0 !important;
|
|
|
|
|
visibility:hidden !important;
|
|
|
|
|
overflow:hidden !important;
|
|
|
|
|
position:absolute !important;
|
|
|
|
|
z-index:-1000 !important;
|
|
|
|
|
top:0 !important;
|
|
|
|
|
right:0 !important
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
const SIZING_STYLE = [
|
|
|
|
@ -38,11 +38,9 @@ const computedStyleCache = {}
|
|
|
|
|
let hiddenTextarea
|
|
|
|
|
|
|
|
|
|
function calculateNodeStyling (node, useCache = false) {
|
|
|
|
|
const nodeRef = (
|
|
|
|
|
node.getAttribute('id') ||
|
|
|
|
|
node.getAttribute('data-reactid') ||
|
|
|
|
|
node.getAttribute('name')
|
|
|
|
|
)
|
|
|
|
|
const nodeRef = (node.getAttribute('id') ||
|
|
|
|
|
node.getAttribute('data-reactid') ||
|
|
|
|
|
node.getAttribute('name'))
|
|
|
|
|
|
|
|
|
|
if (useCache && computedStyleCache[nodeRef]) {
|
|
|
|
|
return computedStyleCache[nodeRef]
|
|
|
|
@ -50,25 +48,20 @@ function calculateNodeStyling (node, useCache = false) {
|
|
|
|
|
|
|
|
|
|
const style = window.getComputedStyle(node)
|
|
|
|
|
|
|
|
|
|
const boxSizing = (
|
|
|
|
|
const boxSizing =
|
|
|
|
|
style.getPropertyValue('box-sizing') ||
|
|
|
|
|
style.getPropertyValue('-moz-box-sizing') ||
|
|
|
|
|
style.getPropertyValue('-webkit-box-sizing')
|
|
|
|
|
)
|
|
|
|
|
style.getPropertyValue('-moz-box-sizing') ||
|
|
|
|
|
style.getPropertyValue('-webkit-box-sizing')
|
|
|
|
|
|
|
|
|
|
const paddingSize = (
|
|
|
|
|
const paddingSize =
|
|
|
|
|
parseFloat(style.getPropertyValue('padding-bottom')) +
|
|
|
|
|
parseFloat(style.getPropertyValue('padding-top'))
|
|
|
|
|
)
|
|
|
|
|
parseFloat(style.getPropertyValue('padding-top'))
|
|
|
|
|
|
|
|
|
|
const borderSize = (
|
|
|
|
|
const borderSize =
|
|
|
|
|
parseFloat(style.getPropertyValue('border-bottom-width')) +
|
|
|
|
|
parseFloat(style.getPropertyValue('border-top-width'))
|
|
|
|
|
)
|
|
|
|
|
parseFloat(style.getPropertyValue('border-top-width'))
|
|
|
|
|
|
|
|
|
|
const sizingStyle = SIZING_STYLE
|
|
|
|
|
.map(name => `${name}:${style.getPropertyValue(name)}`)
|
|
|
|
|
.join(';')
|
|
|
|
|
const sizingStyle = SIZING_STYLE.map(name => `${name}:${style.getPropertyValue(name)}`).join(';')
|
|
|
|
|
|
|
|
|
|
const nodeInfo = {
|
|
|
|
|
sizingStyle,
|
|
|
|
@ -105,10 +98,10 @@ export default function calculateNodeHeight (
|
|
|
|
|
|
|
|
|
|
// Copy all CSS properties that have an impact on the height of the content in
|
|
|
|
|
// the textbox
|
|
|
|
|
const {
|
|
|
|
|
paddingSize, borderSize,
|
|
|
|
|
boxSizing, sizingStyle,
|
|
|
|
|
} = calculateNodeStyling(uiTextNode, useCache)
|
|
|
|
|
const { paddingSize, borderSize, boxSizing, sizingStyle } = calculateNodeStyling(
|
|
|
|
|
uiTextNode,
|
|
|
|
|
useCache,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Need to have the overflow attribute to hide the scrollbar otherwise
|
|
|
|
|
// text-lines will not calculated properly as the shadow will technically be
|
|
|
|
@ -116,22 +109,22 @@ export default function calculateNodeHeight (
|
|
|
|
|
hiddenTextarea.setAttribute('style', `${sizingStyle};${HIDDEN_TEXTAREA_STYLE}`)
|
|
|
|
|
hiddenTextarea.value = uiTextNode.value || uiTextNode.placeholder || ''
|
|
|
|
|
|
|
|
|
|
let minHeight = -Infinity
|
|
|
|
|
let maxHeight = Infinity
|
|
|
|
|
let minHeight = Number.MIN_SAFE_INTEGER
|
|
|
|
|
let maxHeight = Number.MAX_SAFE_INTEGER
|
|
|
|
|
let height = hiddenTextarea.scrollHeight
|
|
|
|
|
let overflowY
|
|
|
|
|
|
|
|
|
|
if (boxSizing === 'border-box') {
|
|
|
|
|
// border-box: add border, since height = content + padding + border
|
|
|
|
|
// border-box: add border, since height = content + padding + border
|
|
|
|
|
height = height + borderSize
|
|
|
|
|
} else if (boxSizing === 'content-box') {
|
|
|
|
|
// remove padding, since height = content
|
|
|
|
|
// remove padding, since height = content
|
|
|
|
|
height = height - paddingSize
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (minRows !== null || maxRows !== null) {
|
|
|
|
|
// measure height of a textarea with a single row
|
|
|
|
|
hiddenTextarea.value = ''
|
|
|
|
|
// measure height of a textarea with a single row
|
|
|
|
|
hiddenTextarea.value = ' '
|
|
|
|
|
const singleRowHeight = hiddenTextarea.scrollHeight - paddingSize
|
|
|
|
|
if (minRows !== null) {
|
|
|
|
|
minHeight = singleRowHeight * minRows
|
|
|
|
@ -150,6 +143,7 @@ export default function calculateNodeHeight (
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Remove scroll bar flash when autosize without maxRows
|
|
|
|
|
// donot remove in vue
|
|
|
|
|
if (!maxRows) {
|
|
|
|
|
overflowY = 'hidden'
|
|
|
|
|
}
|
|
|
|
|