Skip to content

Commit 1681e1d

Browse files
committed
Bumps to v2.16
1 parent 1c92ea2 commit 1681e1d

15 files changed

+906
-756
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
Changelog
22
=========
3+
## 2.16.0
4+
* The prop `disableOnClickOutside` has been renamed to `disableCloseOnClickOutside`
5+
* The calendar doesn't get closed an open when clicking in the input anymore.
6+
* Fixes errors not finding dates when customizing day rendering.
7+
* Event listeners in `inputProps` now only override default behaviour when returning `false`.
8+
39
## 2.15.0
410
* New `onNavigateBack` and `onNavigateForward` hooks thanks to @DaanDD and @simeg.
511
* Touch improvements by @NicoDos

DateTime.js

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ var assign = require('object-assign'),
55
createClass = require('create-react-class'),
66
moment = require('moment'),
77
React = require('react'),
8-
CalendarContainer = require('./src/CalendarContainer')
8+
CalendarContainer = require('./src/CalendarContainer'),
9+
onClickOutside = require('react-onclickoutside').default
910
;
1011

1112
var viewModes = Object.freeze({
@@ -315,7 +316,7 @@ var Datetime = createClass({
315316
},
316317

317318
updateSelectedDate: function( e, close ) {
318-
var target = e.target,
319+
var target = e.currentTarget,
319320
modifier = 0,
320321
viewDate = this.state.viewDate,
321322
currentDate = this.state.selectedDate || viewDate,
@@ -383,7 +384,7 @@ var Datetime = createClass({
383384
},
384385

385386
handleClickOutside: function() {
386-
if ( this.props.input && this.state.open && !this.props.open && !this.props.disableOnClickOutside ) {
387+
if ( this.props.input && this.state.open && this.props.open === undefined && !this.props.disableCloseOnClickOutside ) {
387388
this.setState({ open: false }, function() {
388389
this.props.onBlur( this.state.selectedDate || this.state.inputValue );
389390
});
@@ -432,6 +433,27 @@ var Datetime = createClass({
432433
return props;
433434
},
434435

436+
overrideEvent: function( handler, action ) {
437+
if ( !this.overridenEvents ) {
438+
this.overridenEvents = {};
439+
}
440+
441+
if ( !this.overridenEvents[handler] ) {
442+
var me = this;
443+
this.overridenEvents[handler] = function( e ) {
444+
var result;
445+
if ( me.props.inputProps && me.props.inputProps[handler] ) {
446+
result = me.props.inputProps[handler]( e );
447+
}
448+
if ( result !== false ) {
449+
action( e );
450+
}
451+
};
452+
}
453+
454+
return this.overridenEvents[handler];
455+
},
456+
435457
render: function() {
436458
// TODO: Make a function or clean up this code,
437459
// logic right now is really hard to follow
@@ -444,10 +466,10 @@ var Datetime = createClass({
444466
var finalInputProps = assign({
445467
type: 'text',
446468
className: 'form-control',
447-
onClick: this.openCalendar,
448-
onFocus: this.openCalendar,
449-
onChange: this.onInputChange,
450-
onKeyDown: this.onInputKey,
469+
onClick: this.overrideEvent( 'onClick', this.openCalendar ),
470+
onFocus: this.overrideEvent( 'onFocus', this.openCalendar ),
471+
onChange: this.overrideEvent( 'onChange', this.onInputChange ),
472+
onKeyDown: this.overrideEvent( 'onKeyDown', this.onInputKey ),
451473
value: this.state.inputValue,
452474
}, this.props.inputProps);
453475
if ( this.props.renderInput ) {
@@ -459,18 +481,27 @@ var Datetime = createClass({
459481
className += ' rdtStatic';
460482
}
461483

462-
if ( this.state.open )
484+
if ( this.props.open || (this.props.open === undefined && this.state.open ) )
463485
className += ' rdtOpen';
464486

465-
return React.createElement( 'div', { className: className }, children.concat(
487+
return React.createElement( ClickableWrapper, {className: className, onClickOut: this.handleClickOutside}, children.concat(
466488
React.createElement( 'div',
467489
{ key: 'dt', className: 'rdtPicker' },
468-
React.createElement( CalendarContainer, { view: this.state.currentView, viewProps: this.getComponentProps(), onClickOutside: this.handleClickOutside })
490+
React.createElement( CalendarContainer, { view: this.state.currentView, viewProps: this.getComponentProps() })
469491
)
470492
));
471493
}
472494
});
473495

496+
var ClickableWrapper = onClickOutside( createClass({
497+
render: function() {
498+
return React.createElement( 'div', { className: this.props.className }, this.props.children );
499+
},
500+
handleClickOutside: function( e ) {
501+
this.props.onClickOut( e );
502+
}
503+
}));
504+
474505
Datetime.defaultProps = {
475506
className: '',
476507
defaultValue: '',

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ yarn add react-datetime
2121

2222
## Usage
2323

24-
[React.js](http://facebook.github.io/react/) and [Moment.js](http://momentjs.com/) are peer dependencies for react-datetime. These dependencies are not installed along with react-datetime automatically, but your project needs to have them installed in order to make the datepicker work. You can then use the datepicker like in the example below.
24+
[React.js](http://facebook.github.io/react/) and [Moment.js](http://momentjs.com/) are peer dependencies for react-datetime (as well as [Moment.js timezones](https://momentjs.com/timezone/) if you want to use the `displayTimeZone` prop). These dependencies are not installed along with react-datetime automatically, but your project needs to have them installed in order to make the datepicker work. You can then use the datepicker like in the example below.
2525

2626

2727
```js
@@ -50,7 +50,7 @@ render: function() {
5050
| **open** | `boolean` | `null` | Whether to open or close the picker. If not set react-datetime will open the datepicker on input focus and close it on click outside. |
5151
| **locale** | `string` | `null` | Manually set the locale for the react-datetime instance. Moment.js locale needs to be loaded to be used, see [i18n docs](#i18n).
5252
| **utc** | `boolean` | `false` | When true, input time values will be interpreted as UTC (Zulu time) by Moment.js. Otherwise they will default to the user's local timezone.
53-
| **displayTImeZone** | `string` | `null` | When specified, input time values will be displayed in the given time zone. Otherwise they will default to the user's local timezone (unless `utc` specified).
53+
| **displayTimeZone** | `string` | `null` | **Needs [moment's timezone](https://momentjs.com/timezone/) available in your project.** When specified, input time values will be displayed in the given time zone. Otherwise they will default to the user's local timezone (unless `utc` specified).
5454
| **onChange** | `function` | empty function | Callback trigger when the date changes. The callback receives the selected `moment` object as only parameter, if the date in the input is valid. If the date in the input is not valid, the callback receives the value of the input (a string). |
5555
| **onFocus** | `function` | empty function | Callback trigger for when the user opens the datepicker. The callback receives an event of type SyntheticEvent. |
5656
| **onBlur** | `function` | empty function | Callback trigger for when the user clicks outside of the input, simulating a regular onBlur. The callback receives the selected `moment` object as only parameter, if the date in the input is valid. If the date in the input is not valid, the callback returned. |
@@ -69,7 +69,7 @@ render: function() {
6969
| **closeOnSelect** | `boolean` | `false` | When `true`, once the day has been selected, the datepicker will be automatically closed.
7070
| **closeOnTab** | `boolean` | `true` | When `true` and the input is focused, pressing the `tab` key will close the datepicker.
7171
| **timeConstraints** | `object` | `null` | Add some constraints to the timepicker. It accepts an `object` with the format `{ hours: { min: 9, max: 15, step: 2 }}`, this example means the hours can't be lower than `9` and higher than `15`, and it will change adding or subtracting `2` hours everytime the buttons are clicked. The constraints can be added to the `hours`, `minutes`, `seconds` and `milliseconds`.
72-
| **disableOnClickOutside** | `boolean` | `false` | When `true`, keep the datepicker open when click event is triggered outside of component. When `false`, close it.
72+
| **disableCloseOnClickOutside** | `boolean` | `false` | When `true`, keep the datepicker open when click event is triggered outside of component. When `false`, close it.
7373

7474
## i18n
7575
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/).

0 commit comments

Comments
 (0)