From 2d9966db650f59b73e08659f2d8761f1bafb8c76 Mon Sep 17 00:00:00 2001 From: dujiaqi Date: Thu, 21 Sep 2023 16:27:16 +0800 Subject: [PATCH] fix: unable to close the panel use the confirm button --- src/RangePicker.tsx | 1 + src/hooks/useRangeOpen.ts | 5 ++++- tests/range.spec.tsx | 19 ++++++++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/RangePicker.tsx b/src/RangePicker.tsx index 941b5bd8b..be155abaf 100644 --- a/src/RangePicker.tsx +++ b/src/RangePicker.tsx @@ -360,6 +360,7 @@ function InnerRangePicker(props: RangePickerProps) { open, activePickerIndex, changeOnBlur, + needConfirmButton, startInputRef, endInputRef, getValue(selectedValue, 0), diff --git a/src/hooks/useRangeOpen.ts b/src/hooks/useRangeOpen.ts index d5250f3e2..65a6e4f12 100644 --- a/src/hooks/useRangeOpen.ts +++ b/src/hooks/useRangeOpen.ts @@ -29,6 +29,7 @@ export default function useRangeOpen( open: boolean, activePickerIndex: 0 | 1 | undefined, changeOnBlur: boolean, + needConfirmButton: boolean, startInputRef: React.RefObject, endInputRef: React.RefObject, startSelectedValue: any, @@ -93,7 +94,9 @@ export default function useRangeOpen( } } } else if (source === 'confirm' || (source === 'blur' && changeOnBlur)) { - const customNextActiveIndex = afferentOpen ? queryNextIndex(index) : nextActiveIndex; + // dateTime mode does not need help getting the index + const customNextActiveIndex = + afferentOpen && !needConfirmButton ? queryNextIndex(index) : nextActiveIndex; if (customNextActiveIndex !== null) { setFirstTimeOpen(false); diff --git a/tests/range.spec.tsx b/tests/range.spec.tsx index c1f47d48e..554c57836 100644 --- a/tests/range.spec.tsx +++ b/tests/range.spec.tsx @@ -1076,7 +1076,9 @@ describe('Picker.Range', () => { open cellRender={(date, info) => { expect(info.range).toEqual(range); - return date.format('YYYY-MM-DD'); + if (typeof date !== 'number') { + return date.format('YYYY-MM-DD'); + } }} />, ); @@ -1968,4 +1970,19 @@ describe('Picker.Range', () => { expect(onChange).not.toHaveBeenCalled(); }); }); + + it('dateTime mode should be can use a confirm button to close the panel', () => { + const onOpenChange = jest.fn(); + + render( + , + ); + + for (let i = 0; i < 2; i++) { + selectCell(24); + fireEvent.click(document.querySelector('.rc-picker-ok button')); + } + + expect(onOpenChange).toHaveBeenCalledWith(false); + }); });