@@ -6,6 +6,7 @@ export default class ReactNumeric extends React.Component {
66 constructor ( props ) {
77 super ( props ) ;
88 this . getValue = this . getValue . bind ( this ) ;
9+ this . callEventHandler = this . callEventHandler . bind ( this ) ;
910 }
1011 componentDidMount ( ) {
1112 this . autonumeric = new AutoNumeric ( this . input , this . props . value , {
@@ -31,12 +32,21 @@ export default class ReactNumeric extends React.Component {
3132 } ;
3233 return valueMapper [ this . props . outputFormat ] ( this . autonumeric ) ;
3334 }
35+ callEventHandler ( event , eventName ) {
36+ if ( ! this . props [ eventName ] ) return ;
37+ this . props [ eventName ] ( event , this . getValue ( ) ) ;
38+ }
3439 render ( ) {
40+ const { onChange, onBlur, onKeyPress, onKeyUp, onKeyDown} = this . props ;
3541 return (
3642 < input
3743 ref = { ref => ( this . input = ref ) }
3844 type = { this . props . type }
39- onChange = { event => this . props . onChange ( event , this . getValue ( ) ) }
45+ onChange = { e => this . callEventHandler ( e , 'onChange' ) }
46+ onBlur = { e => this . callEventHandler ( e , 'onBlur' ) }
47+ onKeyPress = { e => this . callEventHandler ( e , 'onKeyPress' ) }
48+ onKeyUp = { e => this . callEventHandler ( e , 'onKeyUp' ) }
49+ onKeyDown = { e => this . callEventHandler ( e , 'onKeyDown' ) }
4050 className = { this . props . className }
4151 style = { this . props . style }
4252 />
@@ -110,7 +120,7 @@ ReactNumeric.propTypes = {
110120 unformatOnHover : PropTypes . bool ,
111121 unformatOnSubmit : PropTypes . bool ,
112122 valuesToStrings : PropTypes . object ,
113- wheelOn : PropTypes . string ,
123+ wheelOn : PropTypes . oneOf ( [ "focus" , "hover" ] ) ,
114124 wheelStep : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . number ] ) ,
115125 preDefined : PropTypes . object
116126} ;
0 commit comments