Skip to content

Commit

Permalink
feat: add onChange for Calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
tangjinzhou authored and afc163 committed Jul 30, 2018
1 parent b8b9aeb commit 92dc0dc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions components/calendar/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ When data is in the form of dates, such as schedules, timetables, prices calenda
| value | The current selected date | [moment](http://momentjs.com/) | current date |
| onPanelChange | Callback for when panel changes | function(date: moment, mode: string) | - |
| onSelect | Callback for when a date is selected | function(date: moment) | - |
| onChange | Callback for when date changes | function(date: moment) | - |
8 changes: 7 additions & 1 deletion components/calendar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface CalendarProps {
style?: React.CSSProperties;
onPanelChange?: (date?: moment.Moment, mode?: CalendarMode) => void;
onSelect?: (date?: moment.Moment) => void;
onChange?: (date?: moment.Moment) => void;
disabledDate?: (current: moment.Moment) => boolean;
validRange ?: [moment.Moment, moment.Moment];
}
Expand All @@ -53,6 +54,7 @@ export default class Calendar extends React.Component<CalendarProps, CalendarSta
mode: 'month',
onSelect: noop,
onPanelChange: noop,
onChange: noop,
};

static propTypes = {
Expand All @@ -68,6 +70,7 @@ export default class Calendar extends React.Component<CalendarProps, CalendarSta
onPanelChange: PropTypes.func,
value: PropTypes.object,
onSelect: PropTypes.func,
onChange: PropTypes.func,
};

constructor(props: CalendarProps) {
Expand Down Expand Up @@ -157,10 +160,13 @@ export default class Calendar extends React.Component<CalendarProps, CalendarSta
}

onPanelChange(value: moment.Moment, mode: CalendarMode | undefined) {
const { onPanelChange } = this.props;
const { onPanelChange, onChange } = this.props;
if (onPanelChange) {
onPanelChange(value, mode);
}
if (onChange && value !== this.state.value) {
onChange(value);
}
}

onSelect = (value: moment.Moment) => {
Expand Down
1 change: 1 addition & 0 deletions components/calendar/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ title: Calendar
| value | 展示日期 | [moment](http://momentjs.com/) | 当前日期 |
| onPanelChange | 日期面板变化回调 | function(date: moment, mode: string) ||
| onSelect | 点击选择日期回调 | function(date: moment) ||
| onChange | 日期变化回调 | function(date: moment) ||

0 comments on commit 92dc0dc

Please sign in to comment.