mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-01 03:29:39 +08:00
fix calendar-onPanelChange some time not trigger (#15063)
This commit is contained in:
parent
9e8bddd864
commit
ed1872fe08
@ -147,4 +147,18 @@ describe('Calendar', () => {
|
||||
expect(wrapper.render()).toMatchSnapshot();
|
||||
MockDate.reset();
|
||||
});
|
||||
|
||||
it('should trigger onPanelChange when click last month of date', () => {
|
||||
const onPanelChange = jest.fn();
|
||||
const date = new Moment('1990-09-03');
|
||||
const wrapper = mount(<Calendar onPanelChange={onPanelChange} value={date} />);
|
||||
|
||||
wrapper
|
||||
.find('.ant-fullcalendar-cell')
|
||||
.at(0)
|
||||
.simulate('click');
|
||||
|
||||
expect(onPanelChange).toBeCalled();
|
||||
expect(onPanelChange.mock.calls[0][0].month()).toEqual(date.month() - 1);
|
||||
});
|
||||
});
|
||||
|
@ -128,15 +128,21 @@ export default class Calendar extends React.Component<CalendarProps, CalendarSta
|
||||
};
|
||||
|
||||
setValue = (value: moment.Moment, way: 'select' | 'changePanel') => {
|
||||
const prevValue = this.props.value || this.state.value;
|
||||
const { mode } = this.state;
|
||||
|
||||
if (!('value' in this.props)) {
|
||||
this.setState({ value });
|
||||
}
|
||||
if (way === 'select') {
|
||||
if (prevValue && prevValue.month() !== value.month()) {
|
||||
this.onPanelChange(value, mode);
|
||||
}
|
||||
if (this.props.onSelect) {
|
||||
this.props.onSelect(value);
|
||||
}
|
||||
} else if (way === 'changePanel') {
|
||||
this.onPanelChange(value, this.state.mode);
|
||||
this.onPanelChange(value, mode);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user