Skip to content

Commit f729830

Browse files
gvelosimeg
authored andcommitted
Fix onFocus() and onBlur() being triggered on inconsistent state
See arqex#162 for a step-by-step explanation to why this change is needed.
1 parent 851b445 commit f729830

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

DateTime.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,20 +318,23 @@ var Datetime = React.createClass({
318318

319319
openCalendar: function() {
320320
if (!this.state.open) {
321-
this.props.onFocus();
322-
this.setState({ open: true });
321+
this.setState({ open: true }, function() {
322+
this.props.onFocus();
323+
});
323324
}
324325
},
325326

326327
closeCalendar: function() {
327-
this.setState({ open: false });
328-
this.props.onBlur( this.state.selectedDate || this.state.inputValue );
328+
this.setState({ open: false }, function () {
329+
this.props.onBlur( this.state.selectedDate || this.state.inputValue );
330+
});
329331
},
330332

331333
handleClickOutside: function(){
332334
if ( this.props.input && this.state.open && !this.props.open ){
333-
this.setState({ open: false });
334-
this.props.onBlur( this.state.selectedDate || this.state.inputValue );
335+
this.setState({ open: false }, function() {
336+
this.props.onBlur( this.state.selectedDate || this.state.inputValue );
337+
});
335338
}
336339
},
337340

0 commit comments

Comments
 (0)