Skip to content

Commit

Permalink
Fixed #2160 - New Calendar focus and blur events
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed Feb 14, 2022
1 parent 5eb30ca commit 54ea5a2
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 11 deletions.
24 changes: 23 additions & 1 deletion api-generator/components/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
10 changes: 10 additions & 0 deletions src/components/calendar/Calendar.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CalendarProps, CalendarSlots, CalendarEmits> { }
Expand Down
21 changes: 12 additions & 9 deletions src/components/calendar/Calendar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -355,7 +355,7 @@ export default {
}
if (this.mask) {
this.destroyMask();
this.destroyMask();
}
this.destroyResponsiveStyleElement();
Expand Down Expand Up @@ -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;
}
}
}
}
Expand Down Expand Up @@ -2140,7 +2140,7 @@ export default {
}
},
onContainerButtonKeydown(event) {
switch (event.which) {
switch (event.which) {
//tab
case 9:
this.trapFocus(event);
Expand All @@ -2155,7 +2155,7 @@ export default {
default:
//Noop
break;
}
}
},
onInput(event) {
try {
Expand All @@ -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) {
Expand Down
12 changes: 11 additions & 1 deletion src/views/calendar/CalendarDoc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ export default {
<tbody>
<tr>
<td>input</td>
<td>event</td>
<td>event: Input Event</td>
<td>Callback to invoke when input field is being typed.</td>
</tr>
<tr>
Expand Down Expand Up @@ -501,6 +501,16 @@ export default {
</td>
<td>Callback to invoke when a year is changed using the navigators.</td>
</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>
</table>
</div>
Expand Down

0 comments on commit 54ea5a2

Please sign in to comment.