UNPKG

tdesign-vue-next

Version:
72 lines (68 loc) 2.15 kB
/** * tdesign v1.19.2 * (c) 2026 tdesign * @license MIT */ import { toRefs, ref, onBeforeUnmount, watch, nextTick, onMounted } from 'vue'; import { l as useResizeObserver } from '../../_chunks/dep-fbeb2963.mjs'; import 'lodash-es'; import '../../_chunks/dep-47c3cae9.mjs'; import '../../_chunks/dep-b0b422fe.mjs'; import '../../_chunks/dep-e1c62679.mjs'; import '../../_chunks/dep-feed89df.mjs'; import '../../_chunks/dep-5b510fcd.mjs'; import '../../config-provider/hooks/useConfig.mjs'; import '../../config-provider/utils/context.mjs'; import '../../_chunks/dep-e0ab6d55.mjs'; import '../../_chunks/dep-75f265c4.mjs'; import '../../_chunks/dep-67ffcfeb.mjs'; import '../../_chunks/dep-f558ebb8.mjs'; import '../../_chunks/dep-edab0e6a.mjs'; import '../../_chunks/dep-76dddedf.mjs'; import '../../_chunks/dep-d92220c4.mjs'; import '../../_chunks/dep-466a8f31.mjs'; import '../../_chunks/dep-ba214d75.mjs'; import '../../_chunks/dep-e66c0337.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