UNPKG

tdesign-vue-next

Version:
72 lines (68 loc) 2.14 kB
/** * tdesign v1.13.2 * (c) 2025 tdesign * @license MIT */ import { toRefs, ref, onBeforeUnmount, watch, nextTick, onMounted } from 'vue'; import { o as useResizeObserver } from '../../_chunks/dep-9c4aef07.mjs'; import 'lodash-es'; import '../../_chunks/dep-b981148e.mjs'; import '../../_chunks/dep-f1895f5a.mjs'; import '../../_chunks/dep-a81129ec.mjs'; import '../../utils/render-tnode.mjs'; import '../../config-provider/hooks/useConfig.mjs'; import '../../config-provider/utils/context.mjs'; import '../../_chunks/dep-466a0666.mjs'; import '../../_chunks/dep-24ce1cec.mjs'; import '../../_chunks/dep-160caab6.mjs'; import '../../_chunks/dep-e497214e.mjs'; import '../../_chunks/dep-98cd1e2d.mjs'; import '../../_chunks/dep-23a929e8.mjs'; import '../../_chunks/dep-48e13ca0.mjs'; import '../../_chunks/dep-033df8e6.mjs'; import '../../utils/dom.mjs'; import '../../_chunks/dep-20550dcc.mjs'; import '../../_chunks/dep-0bb39574.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