tdesign-vue-next
Version:
TDesign Component for vue-next
54 lines (50 loc) • 1.41 kB
JavaScript
/**
* tdesign v1.11.5
* (c) 2025 tdesign
* @license MIT
*/
import { toRefs, ref, onBeforeUnmount, onMounted, watch, nextTick } from 'vue';
import useResizeObserver from '../../hooks/useResizeObserver.js';
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.js.map