Skip to content

Commit

Permalink
fix: do not select disabled cells after page switch
Browse files Browse the repository at this point in the history
  • Loading branch information
arfedulov committed Dec 31, 2018
1 parent 394470c commit b536d89
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 25 deletions.
1 change: 0 additions & 1 deletion example/calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ class DateTimeForm extends React.Component<any, any> {
clearable={clearable}
value={this.state.dateTime}
iconPosition='left'
minDate={moment('2018-12-31 10:20')}
preserveViewMode={false}
autoComplete='off'
onChange={this.handleChange}
Expand Down
12 changes: 8 additions & 4 deletions src/pickers/MonthPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,22 +208,26 @@ class MonthPicker
this.props.onChange(e, data);
}

protected switchToNextPage = (): void => {
protected switchToNextPage = (e: React.SyntheticEvent,
data: any,
callback: () => void): void => {
this.setState(({ date }) => {
const nextDate = date.clone();
nextDate.add(1, 'year');

return { date: nextDate };
});
}, callback);
}

protected switchToPrevPage = (): void => {
protected switchToPrevPage = (e: React.SyntheticEvent,
data: any,
callback: () => void): void => {
this.setState(({ date }) => {
const prevDate = date.clone();
prevDate.subtract(1, 'year');

return { date: prevDate };
});
}, callback);
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/pickers/YearPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ class YearPicker extends SingleSelectionPicker<YearPickerProps> {
this.props.onChange(e, data);
}

protected switchToNextPage = (e, data, callback): void => {
protected switchToNextPage = (e: React.SyntheticEvent,
data: any,
callback: () => void): void => {
this.setState(({ date }) => {
const nextDate = date.clone();
nextDate.add(YEARS_ON_PAGE, 'year');
Expand All @@ -215,7 +217,9 @@ class YearPicker extends SingleSelectionPicker<YearPickerProps> {
}, callback);
}

protected switchToPrevPage = (e, data, callback): void => {
protected switchToPrevPage = (e: React.SyntheticEvent,
data: any,
callback: () => void): void => {
this.setState(({ date }) => {
const prevDate = date.clone();
prevDate.subtract(YEARS_ON_PAGE, 'year');
Expand Down
12 changes: 8 additions & 4 deletions src/pickers/dayPicker/DatesRangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,22 +236,26 @@ class DatesRangePicker
this.props.onChange(e, data);
}

protected switchToNextPage = (): void => {
protected switchToNextPage = (e: React.SyntheticEvent,
data: any,
callback: () => void): void => {
this.setState(({ date }) => {
const nextDate = date.clone();
nextDate.add(1, 'month');

return { date: nextDate };
});
}, callback);
}

protected switchToPrevPage = (): void => {
protected switchToPrevPage = (e: React.SyntheticEvent,
data: any,
callback: () => void): void => {
this.setState(({ date }) => {
const prevDate = date.clone();
prevDate.subtract(1, 'month');

return { date: prevDate };
});
}, callback);
}
}

Expand Down
12 changes: 8 additions & 4 deletions src/pickers/dayPicker/DayPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,22 +176,26 @@ class DayPicker
this.props.onChange(e, data);
}

protected switchToNextPage = (): void => {
protected switchToNextPage = (e: React.SyntheticEvent,
data: any,
callback: () => void): void => {
this.setState(({ date }) => {
const nextDate = date.clone();
nextDate.add(1, 'month');

return { date: nextDate };
});
}, callback);
}

protected switchToPrevPage = (): void => {
protected switchToPrevPage = (e: React.SyntheticEvent,
data: any,
callback: () => void): void => {
this.setState(({ date }) => {
const prevDate = date.clone();
prevDate.subtract(1, 'month');

return { date: prevDate };
});
}, callback);
}
}

Expand Down
12 changes: 8 additions & 4 deletions src/pickers/timePicker/HourPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,22 +192,26 @@ class HourPicker
this.props.onChange(e, data);
}

protected switchToNextPage = (): void => {
protected switchToNextPage = (e: React.SyntheticEvent,
data: any,
callback: () => void): void => {
this.setState(({ date }) => {
const nextDate = date.clone();
nextDate.add(1, 'day');

return { date: nextDate };
});
}, callback);
}

protected switchToPrevPage = (): void => {
protected switchToPrevPage = (e: React.SyntheticEvent,
data: any,
callback: () => void): void => {
this.setState(({ date }) => {
const prevDate = date.clone();
prevDate.subtract(1, 'day');

return { date: prevDate };
});
}, callback);
}
}

Expand Down
12 changes: 8 additions & 4 deletions src/pickers/timePicker/MinutePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,22 +200,26 @@ class MinutePicker
this.props.onChange(e, data);
}

protected switchToNextPage = (): void => {
protected switchToNextPage = (e: React.SyntheticEvent,
data: any,
callback: () => void): void => {
this.setState(({ date }) => {
const nextDate = date.clone();
nextDate.add(1, 'day');

return { date: nextDate };
});
}, callback);
}

protected switchToPrevPage = (): void => {
protected switchToPrevPage = (e: React.SyntheticEvent,
data: any,
callback: () => void): void => {
this.setState(({ date }) => {
const prevDate = date.clone();
prevDate.subtract(1, 'day');

return { date: prevDate };
});
}, callback);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/views/BaseCalendarView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ export interface CalendarWithOptionalHeaderViewProps {
/** Whether a calendar has header. */
hasHeader: boolean;
/** Called after click on next page button. */
onNextPageBtnClick?: () => void;
onNextPageBtnClick?: (e?: React.SyntheticEvent, data?: any, cb?: () => void) => void;
/** Called after click on previous page button. */
onPrevPageBtnClick?: () => void;
onPrevPageBtnClick?: (e?: React.SyntheticEvent, data?: any, cb?: () => void) => void;
/** Whether to display previous page button as active or disabled. */
hasPrevPage?: boolean;
/** Whether to display next page button as active or disabled. */
Expand Down

0 comments on commit b536d89

Please sign in to comment.