From 54ea5a28a809d3ba596bb2519ea2d0050edff096 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tu=C4=9F=C3=A7e=20K=C3=BC=C3=A7=C3=BCko=C4=9Flu?= Date: Mon, 14 Feb 2022 16:27:31 +0300 Subject: [PATCH] Fixed #2160 - New Calendar focus and blur events --- api-generator/components/calendar.js | 24 +++++++++++++++++++++++- src/components/calendar/Calendar.d.ts | 10 ++++++++++ src/components/calendar/Calendar.vue | 21 ++++++++++++--------- src/views/calendar/CalendarDoc.vue | 12 +++++++++++- 4 files changed, 56 insertions(+), 11 deletions(-) diff --git a/api-generator/components/calendar.js b/api-generator/components/calendar.js index a6f7a817c2..08ba5a366a 100644 --- a/api-generator/components/calendar.js +++ b/api-generator/components/calendar.js @@ -332,7 +332,29 @@ const CalendarEvents = [ description: "New year" } ] - } + }, + { + name: "focus", + description: "Callback to invoke on focus of input field.", + arguments: [ + { + name: "event", + type: "object", + description: "Focus event" + } + ] + }, + { + name: "blur", + description: "Callback to invoke on blur of input field.", + arguments: [ + { + name: "event", + type: "object", + description: "Blur event" + } + ] + }, ]; const CalendarSlots = [ diff --git a/src/components/calendar/Calendar.d.ts b/src/components/calendar/Calendar.d.ts index 56257afa46..e246a69e6c 100755 --- a/src/components/calendar/Calendar.d.ts +++ b/src/components/calendar/Calendar.d.ts @@ -314,6 +314,16 @@ export declare type CalendarEmits = { * @param {CalendarYearChangeEvent} event - Custom year change event. */ 'year-change': (event: CalendarYearChangeEvent) => void; + /** + * Callback to invoke on focus of input field. + * @param {Event} event - Focus event + */ + 'focus': (event: Event) => void; + /** + * Callback to invoke on blur of input field. + * @param {Event} event - Blur event + */ + 'blur': (event: Event) => void; } declare class Calendar extends ClassComponent { } diff --git a/src/components/calendar/Calendar.vue b/src/components/calendar/Calendar.vue index b8aa230a08..3733d39d4c 100755 --- a/src/components/calendar/Calendar.vue +++ b/src/components/calendar/Calendar.vue @@ -150,7 +150,7 @@ import Ripple from 'primevue/ripple'; export default { name: 'Calendar', inheritAttrs: false, - emits: ['show', 'hide', 'month-change', 'year-change', 'date-select', 'update:modelValue', 'today-click', 'clear-click'], + emits: ['show', 'hide', 'input', 'month-change', 'year-change', 'date-select', 'update:modelValue', 'today-click', 'clear-click', 'focus', 'blur'], props: { modelValue: null, selectionMode: { @@ -355,7 +355,7 @@ export default { } if (this.mask) { - this.destroyMask(); + this.destroyMask(); } this.destroyResponsiveStyleElement(); @@ -1237,9 +1237,9 @@ export default { return false; } if (this.maxDate.getMinutes() === minute) { - if (this.maxDate.getSeconds() < second) { - return false; - } + if (this.maxDate.getSeconds() < second) { + return false; + } } } } @@ -2140,7 +2140,7 @@ export default { } }, onContainerButtonKeydown(event) { - switch (event.which) { + switch (event.which) { //tab case 9: this.trapFocus(event); @@ -2155,7 +2155,7 @@ export default { default: //Noop break; - } + } }, onInput(event) { try { @@ -2174,15 +2174,18 @@ export default { this.$emit('input', event); }, - onFocus() { + onFocus(event) { if (this.showOnFocus && this.isEnabled()) { this.overlayVisible = true; } this.focused = true; + this.$emit('focus', event); }, - onBlur() { + onBlur(event) { this.focused = false; this.input.value = this.formatValue(this.modelValue); + + this.$emit('blur', event); }, onKeyDown() { if (event.keyCode === 40 && this.overlay) { diff --git a/src/views/calendar/CalendarDoc.vue b/src/views/calendar/CalendarDoc.vue index bdbf5fc414..6f28945550 100755 --- a/src/views/calendar/CalendarDoc.vue +++ b/src/views/calendar/CalendarDoc.vue @@ -459,7 +459,7 @@ export default { input - event + event: Input Event Callback to invoke when input field is being typed. @@ -501,6 +501,16 @@ export default { Callback to invoke when a year is changed using the navigators. + + focus + event: Focus event + Callback to invoke on focus of input field. + + + blur + event: Blur event + Callback to invoke on blur of input field. +