diff --git a/src/components/common/VnInputDate.vue b/src/components/common/VnInputDate.vue index 0507fddfb..b26306c17 100644 --- a/src/components/common/VnInputDate.vue +++ b/src/components/common/VnInputDate.vue @@ -141,6 +141,16 @@ const formatDate = () => { textColor.value = ''; }; +const didFormat = ref(false); + +const handleBlurOrFocusout = (e) => { + if (!didFormat.value) { + formatDate(); + didFormat.value = true; + nextTick(() => (didFormat.value = false)); + } +}; + const handleEnter = (event) => { formatDate(); @@ -170,7 +180,8 @@ const handleEnter = (event) => { :input-style="{ color: textColor }" @click="isPopupOpen = !isPopupOpen" @keydown="isPopupOpen = false" - @blur="formatDate" + @blur="handleBlurOrFocusout" + @focusout="handleBlurOrFocusout" @keydown.enter.prevent="handleEnter" hide-bottom-space :data-cy="($attrs['data-cy'] ?? $attrs.label) + '_inputDate'"