Fixed #2160 - New Calendar focus and blur events

pull/2164/head
Tuğçe Küçükoğlu 2022-02-14 16:27:31 +03:00 committed by Tuğçe Küçükoğlu
parent 5eb30ca2f2
commit 54ea5a28a8
4 changed files with 56 additions and 11 deletions

View File

@ -332,7 +332,29 @@ const CalendarEvents = [
description: "New year" 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 = [ const CalendarSlots = [

View File

@ -314,6 +314,16 @@ export declare type CalendarEmits = {
* @param {CalendarYearChangeEvent} event - Custom year change event. * @param {CalendarYearChangeEvent} event - Custom year change event.
*/ */
'year-change': (event: CalendarYearChangeEvent) => void; '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<CalendarProps, CalendarSlots, CalendarEmits> { } declare class Calendar extends ClassComponent<CalendarProps, CalendarSlots, CalendarEmits> { }

View File

@ -150,7 +150,7 @@ import Ripple from 'primevue/ripple';
export default { export default {
name: 'Calendar', name: 'Calendar',
inheritAttrs: false, 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: { props: {
modelValue: null, modelValue: null,
selectionMode: { selectionMode: {
@ -2174,15 +2174,18 @@ export default {
this.$emit('input', event); this.$emit('input', event);
}, },
onFocus() { onFocus(event) {
if (this.showOnFocus && this.isEnabled()) { if (this.showOnFocus && this.isEnabled()) {
this.overlayVisible = true; this.overlayVisible = true;
} }
this.focused = true; this.focused = true;
this.$emit('focus', event);
}, },
onBlur() { onBlur(event) {
this.focused = false; this.focused = false;
this.input.value = this.formatValue(this.modelValue); this.input.value = this.formatValue(this.modelValue);
this.$emit('blur', event);
}, },
onKeyDown() { onKeyDown() {
if (event.keyCode === 40 && this.overlay) { if (event.keyCode === 40 && this.overlay) {

View File

@ -459,7 +459,7 @@ export default {
<tbody> <tbody>
<tr> <tr>
<td>input</td> <td>input</td>
<td>event</td> <td>event: Input Event</td>
<td>Callback to invoke when input field is being typed.</td> <td>Callback to invoke when input field is being typed.</td>
</tr> </tr>
<tr> <tr>
@ -501,6 +501,16 @@ export default {
</td> </td>
<td>Callback to invoke when a year is changed using the navigators.</td> <td>Callback to invoke when a year is changed using the navigators.</td>
</tr> </tr>
<tr>
<td>focus</td>
<td>event: Focus event</td>
<td>Callback to invoke on focus of input field.</td>
</tr>
<tr>
<td>blur</td>
<td>event: Blur event</td>
<td>Callback to invoke on blur of input field.</td>
</tr>
</tbody> </tbody>
</table> </table>
</div> </div>