UNPKG

tdesign-vue-next

Version:
72 lines (68 loc) 2.15 kB
/** * tdesign v1.20.2 * (c) 2026 tdesign * @license MIT */ import { toRefs, ref, onBeforeUnmount, watch, nextTick, onMounted } from 'vue'; import { l as useResizeObserver } from '../../_chunks/dep-9ce910b6.mjs'; import 'lodash-es'; import '../../_chunks/dep-557b68dd.mjs'; import '../../_chunks/dep-26d65784.mjs'; import '../../_chunks/dep-f038e2b4.mjs'; import '../../_chunks/dep-05bddb06.mjs'; import '../../_chunks/dep-57027bda.mjs'; import '../../config-provider/hooks/useConfig.mjs'; import '../../config-provider/utils/context.mjs'; import '../../_chunks/dep-57949dcd.mjs'; import '../../_chunks/dep-cafb5eac.mjs'; import '../../_chunks/dep-f1da7269.mjs'; import '../../_chunks/dep-ea5fbe21.mjs'; import '../../_chunks/dep-192d0c88.mjs'; import '../../_chunks/dep-652c99fe.mjs'; import '../../_chunks/dep-5b369203.mjs'; import '../../_chunks/dep-a4f55e3b.mjs'; import '../../_chunks/dep-98dac781.mjs'; import '../../_chunks/dep-920eff5b.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