tdesign-vue-next
Version:
TDesign Component for vue-next
72 lines (68 loc) • 2.15 kB
JavaScript
/**
* tdesign v1.20.3
* (c) 2026 tdesign
* @license MIT
*/
import { toRefs, ref, onBeforeUnmount, watch, nextTick, onMounted } from 'vue';
import { l as useResizeObserver } from '../../_chunks/dep-5975d369.mjs';
import 'lodash-es';
import '../../_chunks/dep-adf8ce39.mjs';
import '../../_chunks/dep-390963eb.mjs';
import '../../_chunks/dep-d84a2ec7.mjs';
import '../../_chunks/dep-12b4e978.mjs';
import '../../_chunks/dep-0841ee8f.mjs';
import '../../config-provider/hooks/useConfig.mjs';
import '../../config-provider/utils/context.mjs';
import '../../_chunks/dep-cf105282.mjs';
import '../../_chunks/dep-dcbc09c5.mjs';
import '../../_chunks/dep-9fc6972b.mjs';
import '../../_chunks/dep-ff183185.mjs';
import '../../_chunks/dep-a1cbfaae.mjs';
import '../../_chunks/dep-3f53eff0.mjs';
import '../../_chunks/dep-4c65e11b.mjs';
import '../../_chunks/dep-46776e3b.mjs';
import '../../_chunks/dep-07d8f2aa.mjs';
import '../../_chunks/dep-8aebe545.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