Skip to content

Commit 4b2c7ac

Browse files
committed
feat: Emit blur event when inline date picker loses focus (resolves #995)
1 parent e218a08 commit 4b2c7ac

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/VueDatePicker/VueDatePicker.vue

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
@date-update="$emit('date-update', $event)"
6161
@invalid-date="$emit('invalid-date', $event)"
6262
@overlay-toggle="$emit('overlay-toggle', $event)"
63+
@menu-blur="$emit('blur')"
6364
>
6465
<template v-for="(slot, i) in slotList" #[slot]="args" :key="i">
6566
<slot :name="slot" v-bind="{ ...args }" />

src/VueDatePicker/components/DatepickerMenu.vue

+15
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@
167167
'date-update',
168168
'invalid-date',
169169
'overlay-toggle',
170+
'menu-blur',
170171
]);
171172
172173
const props = defineProps({
@@ -202,6 +203,7 @@
202203
const innerMenuRef = ref(null);
203204
const menuMount = ref(false);
204205
const dynCmpRef = ref<any>(null);
206+
const isMenuActive = ref(false);
205207
206208
onMounted(() => {
207209
if (!props.shadow) {
@@ -216,6 +218,7 @@
216218
}
217219
if (menu) {
218220
const stopDefault = (event: Event) => {
221+
isMenuActive.value = true;
219222
if (defaultedConfig.value.allowPreventDefault) {
220223
event.preventDefault();
221224
}
@@ -225,10 +228,12 @@
225228
menu.addEventListener('mousedown', stopDefault);
226229
}
227230
}
231+
document.addEventListener('mousedown', handleClickOutside);
228232
});
229233
230234
onUnmounted(() => {
231235
window.removeEventListener('resize', getCalendarWidth);
236+
document.addEventListener('mousedown', handleClickOutside);
232237
});
233238
234239
const getCalendarWidth = (): void => {
@@ -419,6 +424,16 @@
419424
}
420425
};
421426
427+
const handleClickOutside = (event: MouseEvent) => {
428+
if (defaultedInline.value.enabled && !defaultedInline.value.input) {
429+
const activeClick = dpMenuRef.value?.contains(event.target as HTMLElement);
430+
if (!activeClick && isMenuActive.value) {
431+
isMenuActive.value = false;
432+
emit('menu-blur');
433+
}
434+
}
435+
};
436+
422437
defineExpose({
423438
updateMonthYear,
424439
switchView,

0 commit comments

Comments
 (0)