Skip to content

Commit

Permalink
enhancement(Datepicker) implemented input field callback functions ma…
Browse files Browse the repository at this point in the history
  • Loading branch information
gselderslaghs committed Dec 27, 2024
1 parent 1e9c276 commit b599ff2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/datepicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ export interface DatepickerOptions extends BaseOptions {
* @default null
*/
onDraw: (() => void) | null;

/**
* Callback function for interaction with input field.
* @default null
*/
onInputInteraction: (() => void) | null;
/** Field used for internal calculations DO NOT CHANGE IT */
minYear?: number;
/** Field used for internal calculations DO NOT CHANGE IT */
Expand Down Expand Up @@ -245,7 +249,8 @@ const _defaults: DatepickerOptions = {
events: [],
// callback function
onSelect: null,
onDraw: null
onDraw: null,
onInputInteraction: null,
};

export class Datepicker extends Component<DatepickerOptions> {
Expand Down Expand Up @@ -1154,13 +1159,15 @@ export class Datepicker extends Component<DatepickerOptions> {
this.setDateFromInput(e.target as HTMLInputElement);
this.draw();
this.gotoDate(<HTMLElement>e.target === this.el ? this.date : this.endDate);
if (this.options.onInputInteraction) this.options.onInputInteraction.call(this);
};

_handleInputKeydown = (e: KeyboardEvent) => {
if (Utils.keys.ENTER.includes(e.key)) {
e.preventDefault();
this.setDateFromInput(e.target as HTMLInputElement);
this.draw();
if (this.options.onInputInteraction) this.options.onInputInteraction.call(this);
}
};

Expand Down

0 comments on commit b599ff2

Please sign in to comment.