Trigger onOk when click on preset range (#9213)

Close #7747
This commit is contained in:
Wei Zhu 2018-02-04 02:41:02 -06:00 committed by GitHub
parent bebed2c4ae
commit 70f30ef065
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -161,7 +161,13 @@ export default class RangePicker extends React.Component<any, RangePickerState>
if (typeof value === 'function') {
value = value();
}
this.setValue(value, true);
const { onOk } = this.props;
if (onOk) {
onOk(value);
}
}
setValue(value: RangePickerValue, hidePanel?: boolean) {

View File

@ -188,4 +188,18 @@ describe('RangePicker', () => {
input.simulate('change', { target: { value: dateString } });
expect(input.getDOMNode().value).toBe(dateString);
});
it('triggers onOk when click on preset range', () => {
const handleOk = jest.fn();
const range = [moment().subtract(2, 'd'), moment()];
const wrapper = mount(
<RangePicker
ranges={{ 'recent two days': range }}
onOk={handleOk}
/>
);
wrapper.find('.ant-calendar-picker-input').simulate('click');
wrapper.find('.ant-calendar-range-quick-selector a').simulate('click');
expect(handleOk).toBeCalledWith(range);
});
});