Skip to content

Commit 46ff2c4

Browse files
authored
fix: multiple select none current panel should not trigger change (#896)
1 parent d44d7bc commit 46ff2c4

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/PickerInput/SinglePicker.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,11 @@ function Picker<DateType extends object = any>(
441441
const onPanelSelect = (date: DateType) => {
442442
lastOperation('panel');
443443

444+
// Not change values if multiple and current panel is to match with picker
445+
if (multiple && internalMode !== picker) {
446+
return;
447+
}
448+
444449
const nextValues = multiple ? toggleDates(getCalendarValue(), date) : [date];
445450

446451
// Only trigger calendar event but not update internal `calendarValue` state

tests/multiple.spec.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,40 @@ describe('Picker.Multiple', () => {
155155
).toBeFalsy();
156156
});
157157
});
158+
159+
it('click year panel should not select', () => {
160+
const onChange = jest.fn();
161+
const onCalendarChange = jest.fn();
162+
const { container } = render(
163+
<DayPicker multiple onChange={onChange} onCalendarChange={onCalendarChange} needConfirm />,
164+
);
165+
166+
expect(container.querySelector('.rc-picker-multiple')).toBeTruthy();
167+
168+
openPicker(container);
169+
170+
// Select year
171+
fireEvent.click(document.querySelector('.rc-picker-year-btn'));
172+
selectCell(1998);
173+
expect(onChange).not.toHaveBeenCalled();
174+
expect(onCalendarChange).not.toHaveBeenCalled();
175+
176+
// Select Month
177+
selectCell('Oct');
178+
expect(onChange).not.toHaveBeenCalled();
179+
expect(onCalendarChange).not.toHaveBeenCalled();
180+
181+
// Select Date
182+
selectCell(23);
183+
expect(onChange).not.toHaveBeenCalled();
184+
expect(onCalendarChange).toHaveBeenCalledWith(
185+
expect.anything(),
186+
['1998-10-23'],
187+
expect.anything(),
188+
);
189+
190+
// Confirm
191+
fireEvent.click(document.querySelector('.rc-picker-ok button'));
192+
expect(onChange).toHaveBeenCalledWith(expect.anything(), ['1998-10-23']);
193+
});
158194
});

0 commit comments

Comments
 (0)