Skip to content

Commit 50a0c27

Browse files
committed
closeOnSelect now working for controlled datepicker.
1 parent 267a3af commit 50a0c27

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
Changelog
22
=========
3+
## 2.2.1
4+
* Controlled datepicker now working for controlled datepickers
5+
36
## 2.2.0
47
* The picker can be used as a month or year picker just giving a format date without days/months
58
* Updates test suite

DateTime.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ var Datetime = React.createClass({
9292
viewDate: viewDate,
9393
selectedDate: selectedDate,
9494
inputValue: selectedDate ? selectedDate.format( formats.datetime ) : (date || ''),
95-
open: props.open != undefined ? props.open : this.state && this.state.open
95+
open: props.open
9696
};
9797
},
9898

@@ -246,7 +246,7 @@ var Datetime = React.createClass({
246246
viewDate = this.state.viewDate,
247247
currentDate = this.state.selectedDate || viewDate,
248248
date
249-
;
249+
;
250250

251251
if(target.className.indexOf("rdtDay") != -1){
252252
if(target.className.indexOf("rdtNew") != -1)
@@ -278,13 +278,15 @@ var Datetime = React.createClass({
278278
this.setState({
279279
selectedDate: date,
280280
viewDate: date.clone().startOf('month'),
281-
inputValue: date.format( this.state.inputFormat )
282-
}, function () {
283-
if (this.props.closeOnSelect && close) {
284-
this.closeCalendar();
285-
}
281+
inputValue: date.format( this.state.inputFormat ),
282+
open: !(this.props.closeOnSelect && close )
286283
});
287284
}
285+
else {
286+
if (this.props.closeOnSelect && close) {
287+
this.closeCalendar();
288+
}
289+
}
288290

289291
this.props.onChange( date );
290292
},
@@ -298,6 +300,7 @@ var Datetime = React.createClass({
298300

299301
closeCalendar: function() {
300302
this.setState({ open: false });
303+
this.props.onBlur( this.state.selectedDate || this.state.inputValue );
301304
},
302305

303306
handleClickOutside: function(){

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-datetime",
3-
"version": "2.2.0",
3+
"version": "2.2.1",
44
"description": "A lightweight but complete datetime picker React.js component.",
55
"homepage": "https://github.com/arqex/react-datetime",
66
"repository": {

0 commit comments

Comments
 (0)