Fix calendar internal select source type (#42459)

* fix: pass panelMode as source type to internal select trigger

* test: add test case for triggering select source with panelMode

* test: update test to pass correct value to check

* test: fix passing value to test

* test: update test in proper select.test file

* test: update test case

---------

Co-authored-by: 二货机器人 <smith3816@gmail.com>
This commit is contained in:
Hector Ayala 2023-05-22 06:48:28 -04:00 committed by GitHub
parent c1dbcae764
commit 5bbd13d2c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -85,11 +85,15 @@ describe('Calendar.onSelect', () => {
const onPanelChange = jest.fn();
const { container } = render(<Calendar onSelect={onSelect} onPanelChange={onPanelChange} />);
// Default is month radio
fireEvent.click(container.querySelector('.ant-picker-cell')!);
expect(onSelect).toHaveBeenCalledWith(expect.anything(), { source: 'date' });
// Click year radio
fireEvent.click(container.querySelectorAll('.ant-radio-button-input')[1]!);
expect(onPanelChange).toHaveBeenCalledWith(expect.anything(), 'year');
fireEvent.click(container.querySelector('.ant-picker-cell')!);
expect(onSelect).toHaveBeenCalledWith(expect.anything(), { source: 'date' });
expect(onSelect).toHaveBeenCalledWith(expect.anything(), { source: 'month' });
});
});

View File

@ -339,7 +339,7 @@ function generateCalendar<DateType>(generateConfig: GenerateConfig<DateType>) {
generateConfig={generateConfig}
cellRender={mergedCellRender}
onSelect={(nextDate) => {
onInternalSelect(nextDate, 'date');
onInternalSelect(nextDate, panelMode);
}}
mode={panelMode}
picker={panelMode}