Skip to content

Commit 418642a

Browse files
authored
fix: range picker saves only last changed date (#830)
* 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
1 parent 097aafd commit 418642a

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/PickerInput/RangePicker.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,10 @@ function RangePicker<DateType extends object = any>(
634634

635635
const onSelectorBlur: SelectorProps['onBlur'] = (event, index) => {
636636
triggerOpen(false);
637+
if (!needConfirm) {
638+
const nextIndex = nextActiveIndex(calendarValue);
639+
flushSubmit(activeIndex, nextIndex === null);
640+
}
637641

638642
onSharedBlur(event, index);
639643
};

tests/range.spec.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,4 +1914,34 @@ describe('Picker.Range', () => {
19141914

19151915
expect(onOpenChange).toHaveBeenCalledWith(false);
19161916
});
1917+
1918+
it('should save both dates, but not only the last that was changed without submit, enter, tab, etc.', async () => {
1919+
const { container } = render(<DayRangePicker />);
1920+
1921+
act(() => {
1922+
fireEvent.focus(container.querySelectorAll('input')[0]);
1923+
fireEvent.change(container.querySelectorAll('input')[0], {
1924+
target: {
1925+
value: '2024-06-13',
1926+
},
1927+
});
1928+
fireEvent.blur(container.querySelectorAll('input')[0]);
1929+
1930+
fireEvent.focus(container.querySelectorAll('input')[1]);
1931+
fireEvent.change(container.querySelectorAll('input')[1], {
1932+
target: {
1933+
value: '2024-06-15',
1934+
},
1935+
});
1936+
1937+
fireEvent.keyDown(container.querySelectorAll('input')[1], {
1938+
key: 'Enter',
1939+
code: 'Enter',
1940+
});
1941+
1942+
});
1943+
1944+
expect(container.querySelectorAll('input')[1].value).toBe('2024-06-15');
1945+
expect(container.querySelectorAll('input')[0].value).toBe('2024-06-13');
1946+
});
19171947
});

0 commit comments

Comments
 (0)