Skip to content

Commit 458a9a7

Browse files
committed
fix: Tab submit not updating model-value when clear button is visible (fixes #961)
1 parent db5f651 commit 458a9a7

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

src/VueDatePicker/components/DatepickerInput.vue

+6-16
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
@blur="handleBlur"
4444
@focus="handleFocus"
4545
@keypress="handleKeyPress"
46-
@keydown="handleKeyPress($event, true)"
46+
@keydown="handleKeyPress($event)"
4747
@paste="handlePaste"
4848
/>
4949
<div @click="emit('toggle')">
@@ -62,11 +62,9 @@
6262
/></span>
6363
<button
6464
v-if="clearable && !$slots['clear-icon'] && inputValue && !disabled && !readonly"
65-
ref="clearBtnRef"
6665
:aria-label="defaultedAriaLabels?.clearInput"
6766
class="dp--clear-btn"
6867
type="button"
69-
@blur="clearBtnFocused = false"
7068
@keydown="checkKeyDown($event, () => onClear($event), true, onClearKeydown)"
7169
@click.prevent="onClear($event)"
7270
>
@@ -136,9 +134,7 @@
136134
const parsedDate = ref();
137135
const inputRef = ref<HTMLInputElement | null>(null);
138136
const isFocused = ref(false);
139-
const clearBtnFocused = ref(false);
140137
const textPasted = ref(false);
141-
const clearBtnRef = ref<HTMLElement | null>(null);
142138
143139
const inputClass = computed(
144140
(): DynamicClass => ({
@@ -241,13 +237,8 @@
241237
}
242238
};
243239
244-
const handleTab = (ev: KeyboardEvent, fromInput?: boolean): void => {
245-
if (clearBtnRef.value && fromInput && !clearBtnFocused.value) {
246-
ev.preventDefault();
247-
clearBtnFocused.value = true;
248-
clearBtnRef.value?.focus();
249-
}
250-
if (defaultedTextInput.value.enabled && defaultedTextInput.value.tabSubmit) {
240+
const handleTab = (ev: KeyboardEvent, noParse?: boolean): void => {
241+
if (defaultedTextInput.value.enabled && defaultedTextInput.value.tabSubmit && !noParse) {
251242
parseInput((ev.target as HTMLInputElement).value);
252243
}
253244
@@ -299,9 +290,9 @@
299290
emit('clear');
300291
};
301292
302-
const handleKeyPress = (ev: KeyboardEvent, fromInput?: boolean): void => {
293+
const handleKeyPress = (ev: KeyboardEvent): void => {
303294
if (ev.key === 'Tab') {
304-
handleTab(ev, fromInput);
295+
handleTab(ev);
305296
}
306297
if (ev.key === 'Enter') {
307298
handleEnter(ev);
@@ -322,8 +313,7 @@
322313
323314
const onClearKeydown = (event: KeyboardEvent) => {
324315
if (event.key === EventKey.tab) {
325-
clearBtnFocused.value = false;
326-
handleTab(event);
316+
handleTab(event, true);
327317
}
328318
};
329319

0 commit comments

Comments
 (0)