UNPKG

tdesign-vue-next

Version:
58 lines (52 loc) 1.5 kB
/** * tdesign v1.11.5 * (c) 2025 tdesign * @license MIT */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var Vue = require('vue'); var hooks_useResizeObserver = require('../../hooks/useResizeObserver.js'); var ANIMATION_TIME = 100; function useInputWidth(props, inputRef, innerValue) { var _toRefs = Vue.toRefs(props), autoWidth = _toRefs.autoWidth, placeholder = _toRefs.placeholder; var inputPreRef = Vue.ref(null); var observerTimer = Vue.ref(null); var updateInputWidth = function updateInputWidth() { if (!inputPreRef.value || !inputRef.value) return; inputRef.value.style.width = getComputedStyle(inputPreRef.value).width; }; hooks_useResizeObserver["default"](inputPreRef, function () { if (autoWidth.value) { observerTimer.value = setTimeout(function () { updateInputWidth(); clearTimeout(observerTimer.value); }, ANIMATION_TIME); } }); Vue.onBeforeUnmount(function () { clearTimeout(observerTimer.value); }); var addListeners = function addListeners() { Vue.watch([innerValue, placeholder], function () { if (!autoWidth.value) return; Vue.nextTick(function () { updateInputWidth(); }); }, { immediate: true }); }; Vue.onMounted(function () { if (autoWidth.value) { addListeners(); } }); return { inputPreRef: inputPreRef }; } exports.useInputWidth = useInputWidth; //# sourceMappingURL=useInputWidth.js.map