UNPKG

tdesign-mobile-vue

Version:
64 lines (60 loc) 2.64 kB
/** * tdesign v1.15.1 * (c) 2026 TDesign Group * @license MIT */ import { isNull } from 'lodash-es'; import { calculateNodeSize } from './helper.js'; import '@babel/runtime/helpers/toConsumableArray'; import '@babel/runtime/helpers/objectWithoutProperties'; import '@babel/runtime/helpers/slicedToArray'; import '@babel/runtime/helpers/defineProperty'; var TEXTAREA_STYLE = "\n min-height:0 !important;\n max-height:none !important;\n height:0 !important;\n visibility:hidden !important;\n overflow:hidden !important;\n position:absolute !important;\n z-index:-1000 !important;\n top:0 !important;\n right:0 !important\n"; function calcTextareaHeight(targetElement) { var minRows = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; var maxRows = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; var hiddenTextarea = document.createElement("textarea"); document.body.appendChild(hiddenTextarea); try { var _calculateNodeSize = calculateNodeSize(targetElement), paddingSize = _calculateNodeSize.paddingSize, borderSize = _calculateNodeSize.borderSize, boxSizing = _calculateNodeSize.boxSizing, sizingStyle = _calculateNodeSize.sizingStyle; hiddenTextarea.setAttribute("style", "".concat(sizingStyle, ";").concat(TEXTAREA_STYLE)); hiddenTextarea.value = targetElement.value || targetElement.placeholder || ""; var height = hiddenTextarea.scrollHeight; var result = {}; var isBorderbox = boxSizing === "border-box"; var isContentbox = boxSizing === "content-box"; if (isBorderbox) { height += borderSize; } else if (isContentbox) { height -= paddingSize; } hiddenTextarea.value = ""; var singleRowHeight = hiddenTextarea.scrollHeight - paddingSize; var calcHeight = function calcHeight(rows) { var rowsHeight = singleRowHeight * rows; if (isBorderbox) { rowsHeight = rowsHeight + paddingSize + borderSize; } return rowsHeight; }; if (!isNull(minRows)) { var minHeight = calcHeight(minRows); height = Math.max(minHeight, height); result.minHeight = "".concat(minHeight, "px"); } if (!isNull(maxRows)) { height = Math.min(calcHeight(maxRows), height); } result.height = "".concat(height, "px"); return result; } finally { var _hiddenTextarea$paren; (_hiddenTextarea$paren = hiddenTextarea.parentNode) === null || _hiddenTextarea$paren === void 0 || _hiddenTextarea$paren.removeChild(hiddenTextarea); } } export { calcTextareaHeight as default }; //# sourceMappingURL=calcTextareaHeight.js.map