Files
mini-yu/uni_modules/tdesign-uniapp/components/input/utils.js
lingxiao865 c5af079d8c first commit
2026-02-10 08:05:03 +08:00

39 lines
760 B
JavaScript

import { getCharacterLength, coalesce } from '../common/utils';
export function getInnerMaxLen({
allowInputOverMax,
maxcharacter,
maxlength,
dataValue,
rawValue,
count,
}) {
if (allowInputOverMax) {
return -1;
}
if (!maxcharacter || maxcharacter < 0) {
return maxlength;
}
if (!dataValue) {
return maxcharacter;
}
const { length: realCount } = getCharacterLength('maxcharacter', rawValue, Infinity);
if (realCount >= maxcharacter) {
return dataValue.length;
}
const { length: computedCount } = getCharacterLength(
'maxcharacter',
rawValue,
allowInputOverMax ? Infinity : maxcharacter,
);
const extra = (coalesce(count, computedCount)) - dataValue.length;
return maxcharacter - extra;
}