Skip to content

Commit

Permalink
fix: multiple select none current panel should not trigger change
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Nov 25, 2024
1 parent d44d7bc commit df22ef2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/PickerInput/SinglePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,11 @@ function Picker<DateType extends object = any>(
const onPanelSelect = (date: DateType) => {
lastOperation('panel');

// Not change values if multiple and current panel is to match with picker
if (multiple && internalMode !== picker) {
return;
}

const nextValues = multiple ? toggleDates(getCalendarValue(), date) : [date];

// Only trigger calendar event but not update internal `calendarValue` state
Expand Down
36 changes: 36 additions & 0 deletions tests/multiple.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,40 @@ describe('Picker.Multiple', () => {
).toBeFalsy();
});
});

it('click year panel should not select', () => {
const onChange = jest.fn();
const onCalendarChange = jest.fn();
const { container } = render(
<DayPicker multiple onChange={onChange} onCalendarChange={onCalendarChange} needConfirm />,
);

expect(container.querySelector('.rc-picker-multiple')).toBeTruthy();

openPicker(container);

// Select year
fireEvent.click(document.querySelector('.rc-picker-year-btn'));
selectCell(1998);
expect(onChange).not.toHaveBeenCalled();
expect(onCalendarChange).not.toHaveBeenCalled();

// Select Month
selectCell('Oct');
expect(onChange).not.toHaveBeenCalled();
expect(onCalendarChange).not.toHaveBeenCalled();

// Select Date
selectCell(23);
expect(onChange).not.toHaveBeenCalled();
expect(onCalendarChange).toHaveBeenCalledWith(
expect.anything(),
['1998-10-23'],
expect.anything(),
);

// Confirm
fireEvent.click(document.querySelector('.rc-picker-ok button'));
expect(onChange).toHaveBeenCalledWith(expect.anything(), ['1998-10-23']);
});
});

0 comments on commit df22ef2

Please sign in to comment.