Skip to content

Commit 1c5c27f

Browse files
authored
fix: RangePicker arrow keys do not start from current date (#124)
1 parent 64c0961 commit 1c5c27f

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

examples/range.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,15 @@ export default () => {
153153
renderExtraFooter={() => <div>extra footer</div>}
154154
/>
155155
</div>
156+
<div style={{ margin: '0 8px' }}>
157+
<h3>Uncontrolled2</h3>
158+
<RangePicker<Moment>
159+
{...sharedProps}
160+
value={undefined}
161+
locale={zhCN}
162+
placeholder={['start...', 'end...']}
163+
/>
164+
</div>
156165
</div>
157166
</div>
158167
);

src/PickerPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ function PickerPanel<DateType>(props: PickerPanelProps<DateType>) {
313313
}
314314
};
315315

316-
if (operationRef) {
316+
if (operationRef && panelPosition !== 'right') {
317317
operationRef.current = {
318318
onKeyDown: onInternalKeyDown,
319319
onClose: () => {

tests/keyboard.spec.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,27 @@ describe('Picker.Keyboard', () => {
443443
.props().value,
444444
).toEqual('');
445445
});
446+
447+
it('move based on current date on first keyboard event', () => {
448+
jest.useFakeTimers();
449+
const onCalendarChange = jest.fn();
450+
const onChange = jest.fn();
451+
const wrapper = mount(
452+
<MomentRangePicker onCalendarChange={onCalendarChange} onChange={onChange} />,
453+
);
454+
455+
// Start Date
456+
wrapper.openPicker();
457+
wrapper
458+
.find('input')
459+
.first()
460+
.simulate('change', { target: { value: '' } });
461+
wrapper.keyDown(KeyCode.TAB);
462+
wrapper.keyDown(KeyCode.RIGHT);
463+
wrapper.keyDown(KeyCode.ENTER);
464+
expect(onCalendarChange.mock.calls[0][1]).toEqual(['1990-09-04', '']);
465+
expect(onChange).not.toHaveBeenCalled();
466+
});
446467
});
447468

448469
it('enter should prevent default to avoid form submit', () => {

0 commit comments

Comments
 (0)