Skip to content

Commit

Permalink
fix: range picker saves only last changed date (#830)
Browse files Browse the repository at this point in the history
* fix: range picker saves only last changed date

* fix: add needConfirm check to onSelectorBlur
when needConfirm is set to true onBlur is not a valid submit operation
  • Loading branch information
wh4t3ver-r authored Jun 19, 2024
1 parent 097aafd commit 418642a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/PickerInput/RangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,10 @@ function RangePicker<DateType extends object = any>(

const onSelectorBlur: SelectorProps['onBlur'] = (event, index) => {
triggerOpen(false);
if (!needConfirm) {
const nextIndex = nextActiveIndex(calendarValue);
flushSubmit(activeIndex, nextIndex === null);
}

onSharedBlur(event, index);
};
Expand Down
30 changes: 30 additions & 0 deletions tests/range.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1914,4 +1914,34 @@ describe('Picker.Range', () => {

expect(onOpenChange).toHaveBeenCalledWith(false);
});

it('should save both dates, but not only the last that was changed without submit, enter, tab, etc.', async () => {
const { container } = render(<DayRangePicker />);

act(() => {
fireEvent.focus(container.querySelectorAll('input')[0]);
fireEvent.change(container.querySelectorAll('input')[0], {
target: {
value: '2024-06-13',
},
});
fireEvent.blur(container.querySelectorAll('input')[0]);

fireEvent.focus(container.querySelectorAll('input')[1]);
fireEvent.change(container.querySelectorAll('input')[1], {
target: {
value: '2024-06-15',
},
});

fireEvent.keyDown(container.querySelectorAll('input')[1], {
key: 'Enter',
code: 'Enter',
});

});

expect(container.querySelectorAll('input')[1].value).toBe('2024-06-15');
expect(container.querySelectorAll('input')[0].value).toBe('2024-06-13');
});
});

0 comments on commit 418642a

Please sign in to comment.