Skip to content
This repository was archived by the owner on Apr 17, 2022. It is now read-only.

Commit a11bec4

Browse files
committed
feat: Auto apply text value if auto-apply prop is set (#34)
1 parent a0a9241 commit a11bec4

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Vue3DatePicker/Vue3DatePicker.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
range,
1717
isMenuOpen: isOpen,
1818
pattern: defaultPattern,
19+
autoApply,
1920
}"
2021
v-model:input-value="inputValue"
2122
@clear="clearValue"
2223
@open="openMenu"
2324
@setInputDate="setInputDate"
25+
@selectDate="selectDate"
2426
@close="closeMenu"
2527
>
2628
<template v-for="(slot, i) in inputSlots" #[slot]="args" :key="i">

src/Vue3DatePicker/components/DatepickerInput.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
@keydown.enter="handleEnter"
2828
@keydown.tab="handleTab"
2929
@focus="handleFocus"
30+
@blur="handleBlur"
3031
/>
3132
<span class="dp__input_icon" v-if="$slots['input-icon'] && !hideInputIcon" @click="stopPropagation"
3233
><slot name="input-icon"
@@ -57,7 +58,7 @@
5758
import { CalendarIcon, CancelIcon } from './Icons';
5859
import { isValidDate, parseFreeInput } from '../utils/date-utils';
5960
60-
const emit = defineEmits(['clear', 'open', 'update:inputValue', 'setInputDate', 'close']);
61+
const emit = defineEmits(['clear', 'open', 'update:inputValue', 'setInputDate', 'close', 'selectDate']);
6162
6263
const props = defineProps({
6364
inputValue: { type: String as PropType<string>, default: '' },
@@ -73,6 +74,7 @@
7374
textInput: { type: Boolean as PropType<boolean>, default: false },
7475
textInputOptions: { type: Object as PropType<ITextInputOptions>, default: () => null },
7576
isMenuOpen: { type: Boolean as PropType<boolean>, default: false },
77+
autoApply: { type: Boolean as PropType<boolean>, default: false },
7678
pattern: { type: String as PropType<string>, default: '' },
7779
});
7880
const parsedDate = ref();
@@ -147,6 +149,14 @@
147149
}
148150
};
149151
152+
const handleBlur = (): void => {
153+
if (props.autoApply && props.textInput && parsedDate.value) {
154+
emit('setInputDate', parsedDate.value);
155+
emit('selectDate');
156+
parsedDate.value = null;
157+
}
158+
};
159+
150160
const stopPropagation = (e: Event) => {
151161
e.stopImmediatePropagation();
152162
};

0 commit comments

Comments
 (0)