Skip to content

Commit 8d6a322

Browse files
committed
Merge branch 'podio-feature/close-on-date-selection'
2 parents 795f65d + c22fcc2 commit 8d6a322

File tree

6 files changed

+28
-14
lines changed

6 files changed

+28
-14
lines changed

DateTime.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var Datetime = React.createClass({
2323
propTypes: {
2424
// value: TYPES.object | TYPES.string,
2525
// defaultValue: TYPES.object | TYPES.string,
26+
closeOnSelect: TYPES.bool,
2627
onBlur: TYPES.func,
2728
onChange: TYPES.func,
2829
locale: TYPES.string,
@@ -217,7 +218,7 @@ var Datetime = React.createClass({
217218
this.props.onChange( date );
218219
},
219220

220-
updateSelectedDate: function( e ) {
221+
updateSelectedDate: function( e, close ) {
221222
var target = e.target,
222223
modifier = 0,
223224
viewDate = this.state.viewDate,
@@ -244,6 +245,10 @@ var Datetime = React.createClass({
244245
selectedDate: date,
245246
viewDate: date.clone().startOf('month'),
246247
inputValue: date.format( this.state.inputFormat )
248+
}, function () {
249+
if (this.props.closeOnSelect && close) {
250+
this.closeCalendar();
251+
}
247252
});
248253
}
249254

@@ -254,6 +259,10 @@ var Datetime = React.createClass({
254259
this.setState({ open: true });
255260
},
256261

262+
closeCalendar: function() {
263+
this.setState({ open: false });
264+
},
265+
257266
handleClickOutside: function(){
258267
if( this.props.input && this.state.open && !this.props.open ){
259268
this.setState({ open: false });

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ API
6161
| **renderMonth** | function | DOM.td( month ) | Customize the way that the months are shown in the month picker. The accepted function has the `selectedDate`, the current date and the default calculated `props` for the cell, the `month` and the `year` to be shown, and must return a React component. See [appearance customization](#appearance-customization) |
6262
| **renderYear** | function | DOM.td( year ) | Customize the way that the years are shown in the year picker. The accepted function has the `selectedDate`, the current date and the default calculated `props` for the cell, the `year` to be shown, and must return a React component. See [appearance customization](#appearance-customization) |
6363
| **strictParsing** | boolean | false | Whether to use moment's [strict parsing](http://momentjs.com/docs/#/parsing/string-format/) when parsing input.
64+
| **closeOnSelect** | boolean | false | When `true`, once the day has been selected, the react-datetime will be automatically closed.
6465

6566
## i18n
6667
Different language and date formats are supported by react-datetime. React uses [moment.js](http://momentjs.com/) to format the dates, and the easiest way of changing the language of the calendar is [changing the moment.js locale](http://momentjs.com/docs/#/i18n/changing-locale/).

dist/react-datetime.js

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

dist/react-datetime.min.js

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

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.0.2",
3+
"version": "2.0.3",
44
"description": "A lightweight but complete datetime picker React.js component.",
55
"homepage": "https://github.com/arqex/react-datetime",
66
"repository": {

src/DaysView.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ var DateTimePickerDays = React.createClass({
9393
className: classes
9494
};
9595
if( !disabled )
96-
dayProps.onClick = this.props.updateSelectedDate;
96+
dayProps.onClick = this.updateSelectedDate;
9797

9898
days.push( renderer( dayProps, currentDate, selected ) );
9999

@@ -108,6 +108,10 @@ var DateTimePickerDays = React.createClass({
108108
return weeks;
109109
},
110110

111+
updateSelectedDate: function( event ) {
112+
this.props.updateSelectedDate(event, true);
113+
},
114+
111115
renderDay: function( props, currentDate, selectedDate ){
112116
return DOM.td( props, currentDate.date() );
113117
},

0 commit comments

Comments
 (0)