Skip to content

Commit

Permalink
[DateRangePicker] Fix currentMonthCalendarPosition not scrolling to…
Browse files Browse the repository at this point in the history
… future sibling (mui#14442)

Co-authored-by: Lukas <[email protected]>
  • Loading branch information
GMchris and LukasTy authored Sep 9, 2024
1 parent 6e3ce20 commit 06b8c13
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,23 @@ describe('<DateRangeCalendar />', () => {
clock.runToLast();
expect(getPickerDay('1', 'April 2018')).not.to.equal(null);
});

describe('prop: currentMonthCalendarPosition', () => {
it('should switch to the selected month when changing value from the outside', () => {
const { setProps } = render(
<DateRangeCalendar
value={[adapterToUse.date('2018-01-10'), adapterToUse.date('2018-01-15')]}
currentMonthCalendarPosition={2}
/>,
);

setProps({
value: [adapterToUse.date('2018-02-11'), adapterToUse.date('2018-02-22')],
});
clock.runToLast();
expect(getPickerDay('1', 'February 2018')).not.to.equal(null);
});
});
});

['readOnly', 'disabled'].forEach((prop) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ const DateRangeCalendar = React.forwardRef(function DateRangeCalendar<
return;
}

const displayingMonthRange = calendars - 1;
const displayingMonthRange = calendars - currentMonthCalendarPosition;
const currentMonthNumber = utils.getMonth(calendarState.currentMonth);
const requestedMonthNumber = utils.getMonth(date);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ describe('<MobileDateRangePicker />', () => {
);

// Open the picker
openPicker({ type: 'date-range', variant: 'mobile', initialFocus: 'start' });
await openPicker({
type: 'date-range',
variant: 'mobile',
initialFocus: 'start',
click: user.click,
});
expect(onChange.callCount).to.equal(0);
expect(onAccept.callCount).to.equal(0);
expect(onClose.callCount).to.equal(0);
Expand Down Expand Up @@ -133,7 +138,12 @@ describe('<MobileDateRangePicker />', () => {
);

// Open the picker
openPicker({ type: 'date-range', variant: 'mobile', initialFocus: 'end' });
await openPicker({
type: 'date-range',
variant: 'mobile',
initialFocus: 'end',
click: user.click,
});
expect(onChange.callCount).to.equal(0);
expect(onAccept.callCount).to.equal(0);
expect(onClose.callCount).to.equal(0);
Expand Down Expand Up @@ -165,7 +175,12 @@ describe('<MobileDateRangePicker />', () => {
/>,
);

openPicker({ type: 'date-range', variant: 'mobile', initialFocus: 'end' });
await openPicker({
type: 'date-range',
variant: 'mobile',
initialFocus: 'end',
click: user.click,
});

// Change the end date
await user.click(screen.getByRole('gridcell', { name: '3' }));
Expand Down Expand Up @@ -196,7 +211,12 @@ describe('<MobileDateRangePicker />', () => {
/>,
);

openPicker({ type: 'date-range', variant: 'mobile', initialFocus: 'start' });
await openPicker({
type: 'date-range',
variant: 'mobile',
initialFocus: 'start',
click: user.click,
});

// Change the start date (already tested)
await user.click(screen.getByRole('gridcell', { name: '3' }));
Expand Down Expand Up @@ -229,7 +249,12 @@ describe('<MobileDateRangePicker />', () => {
/>,
);

openPicker({ type: 'date-range', variant: 'mobile', initialFocus: 'start' });
await openPicker({
type: 'date-range',
variant: 'mobile',
initialFocus: 'start',
click: user.click,
});

// Change the start date (already tested)
await user.click(screen.getByRole('gridcell', { name: '3' }));
Expand Down Expand Up @@ -263,7 +288,12 @@ describe('<MobileDateRangePicker />', () => {
/>,
);

openPicker({ type: 'date-range', variant: 'mobile', initialFocus: 'start' });
await openPicker({
type: 'date-range',
variant: 'mobile',
initialFocus: 'start',
click: user.click,
});

// Clear the date
await user.click(screen.getByText(/clear/i));
Expand All @@ -290,7 +320,12 @@ describe('<MobileDateRangePicker />', () => {
/>,
);

openPicker({ type: 'date-range', variant: 'mobile', initialFocus: 'start' });
await openPicker({
type: 'date-range',
variant: 'mobile',
initialFocus: 'start',
click: user.click,
});

// Clear the date
await user.click(screen.getByText(/clear/i));
Expand Down

0 comments on commit 06b8c13

Please sign in to comment.