Skip to content

Commit 2188abf

Browse files
committed
add onBlur, onKeyPress, onKeyUp, onKeyDown props
1 parent f0da950 commit 2188abf

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

docs/dist/index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>react-date-range</title>
6+
</head>
7+
<body>
8+
<script type="text/javascript" src="main.js"></script></body>
9+
</html>

docs/dist/main.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)