Skip to content

Commit

Permalink
Merge 2d9966d into efc0bfd
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuiai01 authored Sep 21, 2023
2 parents efc0bfd + 2d9966d commit 3a9eca7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/RangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ function InnerRangePicker<DateType>(props: RangePickerProps<DateType>) {
open,
activePickerIndex,
changeOnBlur,
needConfirmButton,
startInputRef,
endInputRef,
getValue(selectedValue, 0),
Expand Down
5 changes: 4 additions & 1 deletion src/hooks/useRangeOpen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default function useRangeOpen(
open: boolean,
activePickerIndex: 0 | 1 | undefined,
changeOnBlur: boolean,
needConfirmButton: boolean,
startInputRef: React.RefObject<HTMLInputElement>,
endInputRef: React.RefObject<HTMLInputElement>,
startSelectedValue: any,
Expand Down Expand Up @@ -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);
Expand Down
19 changes: 18 additions & 1 deletion tests/range.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}}
/>,
);
Expand Down Expand Up @@ -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(
<MomentRangePicker open showTime onOpenChange={onOpenChange} />,
);

for (let i = 0; i < 2; i++) {
selectCell(24);
fireEvent.click(document.querySelector('.rc-picker-ok button'));
}

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

0 comments on commit 3a9eca7

Please sign in to comment.