Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:Field switch should be locked even when the field already has values in RangePicker with showTime enabled #897

Merged
merged 19 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/PickerInput/hooks/useRangeValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ export function useInnerValue<ValueType extends DateType[], DateType extends obj

// Update merged value
const [isSameMergedDates, isSameStart] = isSameDates(calendarValue(), clone);

if (!isSameMergedDates) {
setCalendarValue(clone);

Expand Down Expand Up @@ -335,7 +334,10 @@ export default function useRangeValue<ValueType extends DateType[], DateType ext

// ============================ Check =============================
function hasSubmitValue(index: number) {
return !!submitValue()[index];
return (
!!submitValue()[index] &&
isSame(generateConfig, locale, submitValue()[index], getCalendarValue()[index], picker)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个不太靠谱,因为相同也可能是选择了就是相同的时间。应该是和那个 activeIndex 记录器一样,在设置时同步记录一下才对

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

);
}

// ============================ Return ============================
Expand Down
34 changes: 34 additions & 0 deletions tests/new-range.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,40 @@ describe('NewPicker.Range', () => {
expect(onChange).toHaveBeenCalledWith(expect.anything(), ['06:00:00', '11:00:00']);
});

it('Field switch should be locked even when the field already has the values', () => {
const onChange = jest.fn();

const { container } = render(<DayRangePicker onChange={onChange} showTime />);
openPicker(container);
selectCell(15);
fireEvent.click(document.querySelector('.rc-picker-ok button'));

selectCell(16);
fireEvent.click(document.querySelector('.rc-picker-ok button'));

expect(onChange).toHaveBeenCalledWith(expect.anything(), [
'1990-09-15 00:00:00',
'1990-09-16 00:00:00',
]);

onChange.mockReset();
openPicker(container, 0);
selectCell(1);
openPicker(container, 1);
expect(container.querySelectorAll('input')[0]).toHaveFocus();
expect(container.querySelectorAll('input')[1]).not.toHaveFocus();

fireEvent.click(document.querySelector('.rc-picker-ok button'));
openPicker(container, 1);
expect(container.querySelectorAll('input')[1]).toHaveFocus();
selectCell(2);
fireEvent.click(document.querySelector('.rc-picker-ok button'));
expect(onChange).toHaveBeenCalledWith(expect.anything(), [
'1990-09-01 00:00:00',
'1990-09-02 00:00:00',
]);
});

it('double click to confirm if needConfirm', () => {
const onChange = jest.fn();

Expand Down