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: RangePicker switch field should keep the time sync with date #769

Merged
merged 3 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion src/PickerPanel/TimePanel/TimePanelBody/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export default function TimePanelBody<DateType extends object = any>(
// ========================= Column =========================
// Create a template date for the trigger change event
const triggerDateTmpl = React.useMemo(() => {
let tmpl = pickerValue || generateConfig.getNow();
let tmpl = value || pickerValue || generateConfig.getNow();

const isNotNull = (num: number) => num !== null && num !== undefined;

Expand All @@ -168,6 +168,7 @@ export default function TimePanelBody<DateType extends object = any>(

return tmpl;
}, [
value,
pickerValue,
hour,
minute,
Expand Down
24 changes: 24 additions & 0 deletions tests/new-range.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1240,4 +1240,28 @@ describe('NewPicker.Range', () => {
render(<DayRangePicker picker="week" value={[dayjs(), dayjs().add(21, 'days')]} open />);
expect(document.querySelector('.rc-picker-cell-range-start')).toBeFalsy();
});

it('click time should not modify date', async () => {
const onChange = jest.fn();
const { container } = render(
<DayRangePicker showTime value={[dayjs(), dayjs().add(21, 'days')]} onChange={onChange} />,
);

openPicker(container);

// Start
fireEvent.click(document.querySelectorAll('li.rc-picker-time-panel-cell')[2]);
fireEvent.click(document.querySelector('.rc-picker-ok button'));
await waitFakeTimer();

// End
fireEvent.click(document.querySelectorAll('li.rc-picker-time-panel-cell')[2]);
fireEvent.click(document.querySelector('.rc-picker-ok button'));
await waitFakeTimer();

expect(onChange).toHaveBeenCalledWith(expect.anything(), [
'1990-09-03 02:00:00',
'1990-09-24 02:00:00',
]);
});
});
9 changes: 8 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@
"rc-picker": ["src/index.tsx"]
}
},
"include": [".dumirc.ts", "src/**/*.ts", "src/**/*.tsx", "docs/examples/focus.tsx"]
"include": [
".dumirc.ts",
"src/**/*.ts",
"src/**/*.tsx",
"docs/examples/focus.tsx",
"tests/**/*.ts",
"tests/**/*.tsx"
]
}
Loading