Skip to content

Commit d7d4f1b

Browse files
Yuiai01dujiaqi
and
dujiaqi
authored
fix: unable to close the panel use the confirm button (#678)
Co-authored-by: dujiaqi <[email protected]>
1 parent efc0bfd commit d7d4f1b

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/RangePicker.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ function InnerRangePicker<DateType>(props: RangePickerProps<DateType>) {
360360
open,
361361
activePickerIndex,
362362
changeOnBlur,
363+
needConfirmButton,
363364
startInputRef,
364365
endInputRef,
365366
getValue(selectedValue, 0),

src/hooks/useRangeOpen.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export default function useRangeOpen(
2929
open: boolean,
3030
activePickerIndex: 0 | 1 | undefined,
3131
changeOnBlur: boolean,
32+
needConfirmButton: boolean,
3233
startInputRef: React.RefObject<HTMLInputElement>,
3334
endInputRef: React.RefObject<HTMLInputElement>,
3435
startSelectedValue: any,
@@ -93,7 +94,9 @@ export default function useRangeOpen(
9394
}
9495
}
9596
} else if (source === 'confirm' || (source === 'blur' && changeOnBlur)) {
96-
const customNextActiveIndex = afferentOpen ? queryNextIndex(index) : nextActiveIndex;
97+
// dateTime mode does not need help getting the index
98+
const customNextActiveIndex =
99+
afferentOpen && !needConfirmButton ? queryNextIndex(index) : nextActiveIndex;
97100

98101
if (customNextActiveIndex !== null) {
99102
setFirstTimeOpen(false);

tests/range.spec.tsx

+18-1
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,9 @@ describe('Picker.Range', () => {
10761076
open
10771077
cellRender={(date, info) => {
10781078
expect(info.range).toEqual(range);
1079-
return date.format('YYYY-MM-DD');
1079+
if (typeof date !== 'number') {
1080+
return date.format('YYYY-MM-DD');
1081+
}
10801082
}}
10811083
/>,
10821084
);
@@ -1968,4 +1970,19 @@ describe('Picker.Range', () => {
19681970
expect(onChange).not.toHaveBeenCalled();
19691971
});
19701972
});
1973+
1974+
it('dateTime mode should be can use a confirm button to close the panel', () => {
1975+
const onOpenChange = jest.fn();
1976+
1977+
render(
1978+
<MomentRangePicker open showTime onOpenChange={onOpenChange} />,
1979+
);
1980+
1981+
for (let i = 0; i < 2; i++) {
1982+
selectCell(24);
1983+
fireEvent.click(document.querySelector('.rc-picker-ok button'));
1984+
}
1985+
1986+
expect(onOpenChange).toHaveBeenCalledWith(false);
1987+
});
19711988
});

0 commit comments

Comments
 (0)