tdesign-vue-next
Version:
TDesign Component for vue-next
73 lines (69 loc) • 2.2 kB
JavaScript
/**
* tdesign v1.15.2
* (c) 2025 tdesign
* @license MIT
*/
import { toRefs, ref, onBeforeUnmount, watch, nextTick, onMounted } from 'vue';
import { o as useResizeObserver } from '../../_chunks/dep-465c43e8.mjs';
import 'lodash-es';
import '../../_chunks/dep-d0add92f.mjs';
import '../../_chunks/dep-32b59907.mjs';
import '../../_chunks/dep-15464fee.mjs';
import '../../_chunks/dep-d58b61b6.mjs';
import '../../_chunks/dep-779bddf7.mjs';
import '../../config-provider/hooks/useConfig.mjs';
import '../../config-provider/utils/context.mjs';
import '../../_chunks/dep-afae046d.mjs';
import '../../_chunks/dep-8a6c1499.mjs';
import '../../_chunks/dep-5c28ada1.mjs';
import '../../_chunks/dep-614f307d.mjs';
import '../../_chunks/dep-d913bc66.mjs';
import '../../_chunks/dep-1690abc9.mjs';
import '../../_chunks/dep-62c11543.mjs';
import '../../_chunks/dep-27c2b283.mjs';
import '../../_chunks/dep-612a2c2b.mjs';
import '../../_chunks/dep-0bd8597f.mjs';
import '../../_chunks/dep-67238d91.mjs';
var ANIMATION_TIME = 100;
function useInputWidth(props, inputRef, innerValue) {
var _toRefs = toRefs(props),
autoWidth = _toRefs.autoWidth,
placeholder = _toRefs.placeholder;
var inputPreRef = ref(null);
var observerTimer = ref(null);
var updateInputWidth = function updateInputWidth() {
if (!inputPreRef.value || !inputRef.value) return;
inputRef.value.style.width = getComputedStyle(inputPreRef.value).width;
};
useResizeObserver(inputPreRef, function () {
if (autoWidth.value) {
observerTimer.value = setTimeout(function () {
updateInputWidth();
clearTimeout(observerTimer.value);
}, ANIMATION_TIME);
}
});
onBeforeUnmount(function () {
clearTimeout(observerTimer.value);
});
var addListeners = function addListeners() {
watch([innerValue, placeholder], function () {
if (!autoWidth.value) return;
nextTick(function () {
updateInputWidth();
});
}, {
immediate: true
});
};
onMounted(function () {
if (autoWidth.value) {
addListeners();
}
});
return {
inputPreRef: inputPreRef
};
}
export { useInputWidth };
//# sourceMappingURL=useInputWidth.mjs.map