Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed an issue about the component(RangePicker) could not select the … #15427

Merged
merged 8 commits into from
Apr 1, 2019
10 changes: 7 additions & 3 deletions components/date-picker/RangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ export interface RangePickerState {
hoverValue?: RangePickerValue;
}

function getShowDateFromValue(value: RangePickerValue) {
function getShowDateFromValue(value: RangePickerValue, mode?: string | string[]) {
const [start, end] = value;
// value could be an empty array, then we should not reset showDate
if (!start && !end) {
return;
}
const newEnd = end && end.isSame(start, 'month') ? end.clone().add(1, 'month') : end;
return [start, newEnd] as RangePickerValue;
if (mode && mode[0] === 'month') {
return [start, end] as RangePickerValue;
} else {
return [start, newEnd] as RangePickerValue;
alex89lj marked this conversation as resolved.
Show resolved Hide resolved
}
}

function pickerValueAdapter(
Expand Down Expand Up @@ -83,7 +87,7 @@ class RangePicker extends React.Component<any, RangePickerState> {
if (!shallowequal(nextProps.value, prevState.value)) {
state = {
...state,
showDate: getShowDateFromValue(value) || prevState.showDate,
showDate: getShowDateFromValue(value, nextProps.mode) || prevState.showDate,
};
}
}
Expand Down
17 changes: 17 additions & 0 deletions components/date-picker/__tests__/RangePicker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,21 @@ describe('RangePicker', () => {
const wrapper = mount(<RangePicker separator="test" />);
expect(wrapper.render()).toMatchSnapshot();
});

// https://github.com/ant-design/ant-design/issues/13302
it('in "month" mode,left panel and right panel should be the same month', () => {
alex89lj marked this conversation as resolved.
Show resolved Hide resolved
const wrapper = mount(<RangePicker mode={['month', 'month']} />);
wrapper.setProps({ value: [moment(), moment()] });
expect(
wrapper
.find('.ant-calendar-range-picker-input')
.first()
.getDOMNode().value,
).toBe(
wrapper
.find('.ant-calendar-range-picker-input')
.last()
.getDOMNode().value,
);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

弹出来的面板最好也检测一下两边是不是都可以点。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的 我晚点添加下

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这两个 it 用一个 describe 包一起哈~

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的哈 我稍后添加下

});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"prop-types": "^15.6.2",
"raf": "^3.4.0",
"rc-animate": "^2.5.4",
"rc-calendar": "~9.10.3",
"rc-calendar": "~9.11.0",
"rc-cascader": "~0.17.0",
"rc-checkbox": "~2.1.5",
"rc-collapse": "~1.11.1",
Expand Down