|
|
@ -34,15 +34,22 @@ const SIZING_STYLE = [
|
|
|
|
'box-sizing',
|
|
|
|
'box-sizing',
|
|
|
|
];
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
let computedStyleCache = {};
|
|
|
|
export interface NodeType {
|
|
|
|
let hiddenTextarea;
|
|
|
|
sizingStyle: string;
|
|
|
|
|
|
|
|
paddingSize: number;
|
|
|
|
|
|
|
|
borderSize: number;
|
|
|
|
|
|
|
|
boxSizing: string;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let computedStyleCache: {[key: string]: NodeType} = {};
|
|
|
|
|
|
|
|
let hiddenTextarea: HTMLTextAreaElement;
|
|
|
|
|
|
|
|
|
|
|
|
function calculateNodeStyling(node, useCache = false) {
|
|
|
|
function calculateNodeStyling(node: HTMLElement, useCache = false) {
|
|
|
|
const nodeRef = (
|
|
|
|
const nodeRef = (
|
|
|
|
node.getAttribute('id') ||
|
|
|
|
node.getAttribute('id') ||
|
|
|
|
node.getAttribute('data-reactid') ||
|
|
|
|
node.getAttribute('data-reactid') ||
|
|
|
|
node.getAttribute('name')
|
|
|
|
node.getAttribute('name')
|
|
|
|
);
|
|
|
|
) as string;
|
|
|
|
|
|
|
|
|
|
|
|
if (useCache && computedStyleCache[nodeRef]) {
|
|
|
|
if (useCache && computedStyleCache[nodeRef]) {
|
|
|
|
return computedStyleCache[nodeRef];
|
|
|
|
return computedStyleCache[nodeRef];
|
|
|
@ -70,7 +77,7 @@ function calculateNodeStyling(node, useCache = false) {
|
|
|
|
.map(name => `${name}:${style.getPropertyValue(name)}`)
|
|
|
|
.map(name => `${name}:${style.getPropertyValue(name)}`)
|
|
|
|
.join(';');
|
|
|
|
.join(';');
|
|
|
|
|
|
|
|
|
|
|
|
const nodeInfo = {
|
|
|
|
const nodeInfo: NodeType = {
|
|
|
|
sizingStyle,
|
|
|
|
sizingStyle,
|
|
|
|
paddingSize,
|
|
|
|
paddingSize,
|
|
|
|
borderSize,
|
|
|
|
borderSize,
|
|
|
@ -85,7 +92,7 @@ function calculateNodeStyling(node, useCache = false) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default function calculateNodeHeight(
|
|
|
|
export default function calculateNodeHeight(
|
|
|
|
uiTextNode,
|
|
|
|
uiTextNode: HTMLTextAreaElement,
|
|
|
|
useCache = false,
|
|
|
|
useCache = false,
|
|
|
|
minRows: number | null = null,
|
|
|
|
minRows: number | null = null,
|
|
|
|
maxRows: number | null = null,
|
|
|
|
maxRows: number | null = null,
|
|
|
@ -98,7 +105,7 @@ export default function calculateNodeHeight(
|
|
|
|
// Fix wrap="off" issue
|
|
|
|
// Fix wrap="off" issue
|
|
|
|
// https://github.com/ant-design/ant-design/issues/6577
|
|
|
|
// https://github.com/ant-design/ant-design/issues/6577
|
|
|
|
if (uiTextNode.getAttribute('wrap')) {
|
|
|
|
if (uiTextNode.getAttribute('wrap')) {
|
|
|
|
hiddenTextarea.setAttribute('wrap', uiTextNode.getAttribute('wrap'));
|
|
|
|
hiddenTextarea.setAttribute('wrap', uiTextNode.getAttribute('wrap') as string);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
hiddenTextarea.removeAttribute('wrap');
|
|
|
|
hiddenTextarea.removeAttribute('wrap');
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -119,7 +126,7 @@ export default function calculateNodeHeight(
|
|
|
|
let minHeight = Number.MIN_SAFE_INTEGER;
|
|
|
|
let minHeight = Number.MIN_SAFE_INTEGER;
|
|
|
|
let maxHeight = Number.MAX_SAFE_INTEGER;
|
|
|
|
let maxHeight = Number.MAX_SAFE_INTEGER;
|
|
|
|
let height = hiddenTextarea.scrollHeight;
|
|
|
|
let height = hiddenTextarea.scrollHeight;
|
|
|
|
let overflowY;
|
|
|
|
let overflowY: any;
|
|
|
|
|
|
|
|
|
|
|
|
if (boxSizing === 'border-box') {
|
|
|
|
if (boxSizing === 'border-box') {
|
|
|
|
// border-box: add border, since height = content + padding + border
|
|
|
|
// border-box: add border, since height = content + padding + border
|
|
|
|