From 84840fc828db90215c1e41a540b18fcb1ddf4cd2 Mon Sep 17 00:00:00 2001 From: JoaoPedroAS51 Date: Fri, 27 Jun 2025 20:53:03 -0300 Subject: [PATCH] fix: `auto-apply` not working with `text-input` Prevent external value updates from overriding text input while typing, and prevent the menu from closing on auto-apply. Fixes #1106 --- src/VueDatePicker/VueDatePicker.vue | 4 ++-- .../composables/external-internal-mapper.ts | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/VueDatePicker/VueDatePicker.vue b/src/VueDatePicker/VueDatePicker.vue index ebe55186..18998902 100644 --- a/src/VueDatePicker/VueDatePicker.vue +++ b/src/VueDatePicker/VueDatePicker.vue @@ -239,7 +239,7 @@ emitModelValue, formatInputValue, checkBeforeEmit, - } = useExternalInternalMapper(emit, props, isInputFocused); + } = useExternalInternalMapper(emit, props, { isInputFocused, isTextInputDate }); const wrapperClass = computed( (): DynamicClass => ({ @@ -469,7 +469,7 @@ selectDate(); emit('text-submit'); } else if (props.autoApply) { - autoApplyValue(); + autoApplyValue(true); } nextTick().then(() => { isTextInputDate.value = false; diff --git a/src/VueDatePicker/composables/external-internal-mapper.ts b/src/VueDatePicker/composables/external-internal-mapper.ts index 815ff991..e6563d6a 100644 --- a/src/VueDatePicker/composables/external-internal-mapper.ts +++ b/src/VueDatePicker/composables/external-internal-mapper.ts @@ -24,7 +24,11 @@ import { modelTypePredefined } from '@/constants'; /** * Handles values from external to internal and vise versa */ -export const useExternalInternalMapper = (emit: VueEmit, props: AllPropsType, isInputFocused: Ref) => { +export const useExternalInternalMapper = ( + emit: VueEmit, + props: AllPropsType, + { isInputFocused, isTextInputDate }: { isInputFocused: Ref; isTextInputDate: Ref }, +) => { const internalModelValue = ref(); const { defaultedTextInput, defaultedRange, defaultedTz, defaultedMultiDates, getDefaultPattern } = @@ -267,6 +271,9 @@ export const useExternalInternalMapper = (emit: VueEmit, props: AllPropsType, is * Also does the validation of the provided value, if invalid it will use null as a default or an empty value */ const parseExternalModelValue = (value: ModelValue): void => { + // Prevent text input from being overridden by external value while typing + if (isTextInputDate.value) return; + const mappedDate = mapExternalToInternal(value); if (isValidDate(convertType(mappedDate))) {