|
|
|
@ -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') ||
|
|
|
|
|
const nodeRef = (node.getAttribute('id') ||
|
|
|
|
|
node.getAttribute('data-reactid') ||
|
|
|
|
|
node.getAttribute('name')
|
|
|
|
|
)
|
|
|
|
|
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')
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const paddingSize = (
|
|
|
|
|
const paddingSize =
|
|
|
|
|
parseFloat(style.getPropertyValue('padding-bottom')) +
|
|
|
|
|
parseFloat(style.getPropertyValue('padding-top'))
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const borderSize = (
|
|
|
|
|
const borderSize =
|
|
|
|
|
parseFloat(style.getPropertyValue('border-bottom-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,8 +109,8 @@ 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
|
|
|
|
|
|
|
|
|
@ -131,7 +124,7 @@ export default function calculateNodeHeight (
|
|
|
|
|
|
|
|
|
|
if (minRows !== null || maxRows !== null) {
|
|
|
|
|
// measure height of a textarea with a single row
|
|
|
|
|
hiddenTextarea.value = ''
|
|
|
|
|
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'
|
|
|
|
|
}
|
|
|
|
|