Skip to content

Commit

Permalink
bug/minor: events: ignore blur event after keypress has been handled
Browse files Browse the repository at this point in the history
fix #11
  • Loading branch information
NicolasCARPi committed Nov 14, 2024
1 parent b4fa4ad commit f3e7bdf
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,12 @@ export class Malle {
original: HTMLElement;
input: HTMLInputElement|HTMLSelectElement;
innerFun: string;
ignoreBlur: boolean;

constructor(options: Options) {
this.opt = this.normalizeOptions(options);
this.debug(`Options: ${JSON.stringify(this.opt)}`);
this.ignoreBlur = false;
if (this.opt.listenNow) {
this.listen();
}
Expand Down Expand Up @@ -321,6 +323,9 @@ export class Malle {
}

handleBlur(event: Event) {
if (this.ignoreBlur) {
return;
}
// read behavior from options
let blurAction: string = this.opt.onBlur;
// and let element override it
Expand All @@ -334,6 +339,8 @@ export class Malle {
}

handleKeypress(event: KeyboardEvent): boolean {
// reset this global flag
this.ignoreBlur = false;
// ignore it for textarea
if (this.opt.inputType === InputType.Textarea) {
return false;
Expand All @@ -350,6 +357,7 @@ export class Malle {
return;
}
this[enterAction](event);
this.ignoreBlur = true;
return;
}

Expand All @@ -364,6 +372,7 @@ export class Malle {
event.preventDefault();
return;
}
this.ignoreBlur = true;
this[escAction](event);
}
}
Expand Down

0 comments on commit f3e7bdf

Please # to comment.