UNPKG

tdesign-vue-next

Version:
72 lines (68 loc) 2.15 kB
/** * tdesign v1.20.0 * (c) 2026 tdesign * @license MIT */ import { toRefs, ref, onBeforeUnmount, watch, nextTick, onMounted } from 'vue'; import { l as useResizeObserver } from '../../_chunks/dep-6e1ec500.mjs'; import 'lodash-es'; import '../../_chunks/dep-3a6b2289.mjs'; import '../../_chunks/dep-1e8a6a5e.mjs'; import '../../_chunks/dep-7e80b480.mjs'; import '../../_chunks/dep-98b885ec.mjs'; import '../../_chunks/dep-c53b1c81.mjs'; import '../../config-provider/hooks/useConfig.mjs'; import '../../config-provider/utils/context.mjs'; import '../../_chunks/dep-fc168c9c.mjs'; import '../../_chunks/dep-2242b0fd.mjs'; import '../../_chunks/dep-b9ecb840.mjs'; import '../../_chunks/dep-a1cffe73.mjs'; import '../../_chunks/dep-67ace303.mjs'; import '../../_chunks/dep-8768d1f1.mjs'; import '../../_chunks/dep-68c88886.mjs'; import '../../_chunks/dep-dfce43be.mjs'; import '../../_chunks/dep-e25ecc4b.mjs'; import '../../_chunks/dep-d9965fa1.mjs'; var ANIMATION_TIME = 100; function useInputWidth(props, inputRef, innerValue) { var _toRefs = toRefs(props), autoWidth = _toRefs.autoWidth, placeholder = _toRefs.placeholder; var inputPreRef = ref(); 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