Skip to content

Commit

Permalink
pass input event to Accept/Complete callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
uNmAnNeR committed Mar 13, 2020
1 parent 1dafbed commit 624743b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
15 changes: 9 additions & 6 deletions packages/imask/src/controls/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class InputMask {
_onFocus: (Event) => void;
_onClick: (Event) => void;
_cursorChanging: ?TimeoutID;
_inputEvent: ?InputEvent;

/**
@param {MaskElement|HTMLInputElement|HTMLTextAreaElement} el
Expand Down Expand Up @@ -156,11 +157,11 @@ class InputMask {
Fires custom event
@protected
*/
_fireEvent (ev: string) {
_fireEvent (ev: string, ...args: *) {
const listeners = this._listeners[ev];
if (!listeners) return;

listeners.forEach(l => l());
listeners.forEach(l => l(...args));
}

/**
Expand All @@ -182,7 +183,7 @@ class InputMask {
this.el.selectionEnd;
}
set cursorPos (pos: number) {
if (!this.el.isActive) return;
if (!this.el || !this.el.isActive) return;

this.el.select(pos, pos);
this._saveSelection();
Expand Down Expand Up @@ -263,8 +264,8 @@ class InputMask {
@protected
*/
_fireChangeEvents () {
this._fireEvent('accept');
if (this.masked.isComplete) this._fireEvent('complete');
this._fireEvent('accept', this._inputEvent);
if (this.masked.isComplete) this._fireEvent('complete', this._inputEvent);
}

/**
Expand Down Expand Up @@ -309,7 +310,8 @@ class InputMask {
}

/** Handles view input event */
_onInput () {
_onInput (e: InputEvent) {
this._inputEvent = e;
this._abortUpdateCursor();

// fix strange IE behavior
Expand Down Expand Up @@ -342,6 +344,7 @@ class InputMask {

this.updateControl();
this.updateCursor(cursorPos);
delete this._inputEvent;
}

/** Handles view change event and commits model value */
Expand Down
8 changes: 4 additions & 4 deletions packages/react-imask/src/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,12 @@ function IMaskMixin(ComposedComponent) {
else this.maskRef.value = value;
}

_onAccept () {
if (this.props.onAccept) this.props.onAccept(this.maskValue, this.maskRef);
_onAccept (...args) {
if (this.props.onAccept) this.props.onAccept(this.maskValue, this.maskRef, ...args);
}

_onComplete () {
if (this.props.onComplete) this.props.onComplete(this.maskValue, this.maskRef);
_onComplete (...args) {
if (this.props.onComplete) this.props.onComplete(this.maskValue, this.maskRef, ...args);
}
};

Expand Down

0 comments on commit 624743b

Please sign in to comment.