Skip to content

Commit 811788c

Browse files
committed
add posibility to block back || forward on change date
1 parent 2c605fc commit 811788c

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

DateTime.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ declare namespace ReactDatetimeClass {
102102
Callback trigger when the user navigates to the previous month, year or decade.
103103
The callback receives the amount and type ('month', 'year') as parameters.
104104
*/
105-
onNavigateBack?: (amount: number, type: string) => void;
105+
onNavigateBack?: (amount: number, type: string, curDate: any) => void;
106106
/*
107107
Callback trigger when the user navigates to the next month, year or decade.
108108
The callback receives the amount and type ('month', 'year') as parameters.
109109
*/
110-
onNavigateForward?: (amount: number, type: string) => void;
110+
onNavigateForward?: (amount: number, type: string, curDate: any) => void;
111111
/*
112112
The default view to display when the picker is shown. ('years', 'months', 'days', 'time')
113113
*/

DateTime.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,16 +260,18 @@ var Datetime = createClass({
260260
subtractTime: function( amount, type, toSelected ) {
261261
var me = this;
262262
return function() {
263-
me.props.onNavigateBack( amount, type );
264-
me.updateTime( 'subtract', amount, type, toSelected );
263+
if (me.props.onNavigateBack( amount, type, me.state.date )) {
264+
me.updateTime( 'subtract', amount, type, toSelected );
265+
}
265266
};
266267
},
267268

268269
addTime: function( amount, type, toSelected ) {
269270
var me = this;
270271
return function() {
271-
me.props.onNavigateForward( amount, type );
272-
me.updateTime( 'add', amount, type, toSelected );
272+
if (me.props.onNavigateForward( amount, type, me.state.date )) {
273+
me.updateTime('add', amount, type, toSelected);
274+
}
273275
};
274276
},
275277

@@ -465,8 +467,8 @@ Datetime.defaultProps = {
465467
onBlur: function() {},
466468
onChange: function() {},
467469
onViewModeChange: function() {},
468-
onNavigateBack: function() {},
469-
onNavigateForward: function() {},
470+
onNavigateBack: function() { return true; },
471+
onNavigateForward: function() { return true; },
470472
timeFormat: true,
471473
timeConstraints: {},
472474
dateFormat: true,

0 commit comments

Comments
 (0)