Skip to content

Commit 7c5ffd0

Browse files
committed
fix: Focus in on text input with date selects the whole text without selectOnFocus enabled, tabbing to clear button and back clears the input
1 parent fc31e00 commit 7c5ffd0

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

packages/lib/src/VueDatePicker/components/DatePickerInput/DatepickerInput.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
const inputRef = useTemplateRef('dp-input');
135135
const parsedDate = ref<InputParsedDate>(null);
136136
const isFocused = ref(false);
137+
const valueChanged = ref(false);
137138
138139
const inputClass = computed(
139140
(): DynamicClass => ({
@@ -202,6 +203,8 @@
202203
};
203204
204205
const handleInput = (event: Event | string): void => {
206+
valueChanged.value = true;
207+
205208
const value = typeof event === 'string' ? event : (event.target as HTMLInputElement)?.value;
206209
207210
const maskFormat = textInput?.value?.maskFormat;
@@ -266,6 +269,9 @@
266269
nextTick().then(() => {
267270
if (textInput.value.enabled && textInput.value.selectOnFocus) {
268271
inputRef.value?.select();
272+
} else {
273+
const len = inputValue.value.length;
274+
inputRef.value?.setSelectionRange(len, len);
269275
}
270276
});
271277
};
@@ -291,8 +297,12 @@
291297
(rootProps.autoApply && textInput.value.enabled && parsedDate.value && !props.isMenuOpen) ||
292298
(textInput.value.applyOnBlur ? !state.actionInMenu : false)
293299
) {
294-
emit('set-input-date', parsedDate.value);
295-
emit('select-date');
300+
if (valueChanged.value) {
301+
parseInput(inputValue.value);
302+
emit('set-input-date', parsedDate.value);
303+
emit('select-date');
304+
}
305+
valueChanged.value = false;
296306
parsedDate.value = null;
297307
}
298308
};

0 commit comments

Comments
 (0)