Skip to content

Commit 2e520bb

Browse files
committed
fix: respect needConfirm for typed range input blur
1 parent 08a2e63 commit 2e520bb

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

src/PickerInput/RangePicker.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ function RangePicker<DateType extends object = any>(
744744
const lastOp = lastOperation();
745745

746746
// Trade as confirm on field leave
747-
if (!mergedOpen && lastOp === 'input') {
747+
if (!mergedOpen && !needConfirm && lastOp === 'input') {
748748
triggerOpen(false);
749749
triggerPartConfirm(null, true);
750750
}

tests/range.spec.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,32 @@ describe('Picker.Range', () => {
918918
matchValues(container, '', '');
919919
});
920920

921+
it('should not submit typed values on blur before confirm', () => {
922+
const onChange = jest.fn();
923+
const { container } = render(<DayRangePicker showTime allowEmpty onChange={onChange} />);
924+
925+
const startInput = container.querySelectorAll<HTMLInputElement>('input')[0];
926+
927+
startInput.focus();
928+
fireEvent.change(startInput, {
929+
target: {
930+
value: '1990-09-11 00:00:00',
931+
},
932+
});
933+
934+
fireEvent.mouseDown(document.body);
935+
startInput.blur();
936+
937+
for (let i = 0; i < 5; i += 1) {
938+
act(() => {
939+
jest.runAllTimers();
940+
});
941+
}
942+
943+
expect(onChange).not.toHaveBeenCalled();
944+
matchValues(container, '', '');
945+
});
946+
921947
describe('viewDate', () => {
922948
function matchTitle(title: string) {
923949
expect(document.querySelector('.rc-picker-header-view').textContent).toEqual(title);

0 commit comments

Comments
 (0)