Skip to content

fix: auto-apply not working with text-input #1140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/VueDatePicker/VueDatePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
emitModelValue,
formatInputValue,
checkBeforeEmit,
} = useExternalInternalMapper(emit, props, isInputFocused);
} = useExternalInternalMapper(emit, props, { isInputFocused, isTextInputDate });

const wrapperClass = computed(
(): DynamicClass => ({
Expand Down Expand Up @@ -469,7 +469,7 @@
selectDate();
emit('text-submit');
} else if (props.autoApply) {
autoApplyValue();
autoApplyValue(true);
}
nextTick().then(() => {
isTextInputDate.value = false;
Expand Down
9 changes: 8 additions & 1 deletion src/VueDatePicker/composables/external-internal-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>) => {
export const useExternalInternalMapper = (
emit: VueEmit,
props: AllPropsType,
{ isInputFocused, isTextInputDate }: { isInputFocused: Ref<boolean>; isTextInputDate: Ref<boolean> },
) => {
const internalModelValue = ref();

const { defaultedTextInput, defaultedRange, defaultedTz, defaultedMultiDates, getDefaultPattern } =
Expand Down Expand Up @@ -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))) {
Expand Down