diff --git a/packages/imask/src/controls/input.js b/packages/imask/src/controls/input.js index e03aa095..6a67b0a4 100644 --- a/packages/imask/src/controls/input.js +++ b/packages/imask/src/controls/input.js @@ -40,6 +40,7 @@ class InputMask { _onFocus: (Event) => void; _onClick: (Event) => void; _cursorChanging: ?TimeoutID; + _inputEvent: ?InputEvent; /** @param {MaskElement|HTMLInputElement|HTMLTextAreaElement} el @@ -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)); } /** @@ -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(); @@ -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); } /** @@ -309,7 +310,8 @@ class InputMask { } /** Handles view input event */ - _onInput () { + _onInput (e: InputEvent) { + this._inputEvent = e; this._abortUpdateCursor(); // fix strange IE behavior @@ -342,6 +344,7 @@ class InputMask { this.updateControl(); this.updateCursor(cursorPos); + delete this._inputEvent; } /** Handles view change event and commits model value */ diff --git a/packages/react-imask/src/mixin.js b/packages/react-imask/src/mixin.js index 0ef6ecb9..be4e0428 100644 --- a/packages/react-imask/src/mixin.js +++ b/packages/react-imask/src/mixin.js @@ -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); } };