Skip to content

Commit

Permalink
fix: avoid set null values
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielcursino committed Nov 19, 2021
1 parent ecbad82 commit 3d7f3fd
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface MaskData {
focus: boolean;
input: string;
inputRaw: string;
output: string;
output: string | null;
}

export class MaskCore {
Expand Down Expand Up @@ -61,7 +61,7 @@ export class MaskCore {

this.options.init && this.options.init(this.data);

this.el.value = this.data.output;
this.el.value = this.data.output as string;

this.update();
}
Expand Down Expand Up @@ -111,23 +111,23 @@ export class MaskCore {
}

private update(focus = false, changeCursor = true) {
this.el.value = this.data.output;
if (this.data.output !== null) this.el.value = this.data.output;

if (changeCursor) this.setCursorPosition(this.data.cursorPosition, focus ? 25 : undefined);

this.dispatchEvent();
}

private focus() {
this.data.input = this.el.value;
this.reset();

this.options.focus && this.options.focus(this.data);

this.format(true);
}

private blur() {
this.data.input = this.el.value;
this.reset();

this.options.blur && this.options.blur(this.data);

Expand All @@ -141,13 +141,18 @@ export class MaskCore {
}

private mouseout() {
this.data.input = this.el.value;
this.reset();

this.options.mouseout && this.options.mouseout(this.data);

this.update(false, false);
}

private reset() {
this.data.input = this.el.value;
this.data.output = null;
}

private setCursorPosition(index: number, timeout?: number) {
if (timeout || (this.isMobile && this.data.delete)) setTimeout(() => this.el.setSelectionRange(index, index), timeout);
else this.el.setSelectionRange(index, index);
Expand Down

0 comments on commit 3d7f3fd

Please sign in to comment.