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

[DateRangePicker] Fix currentMonthCalendarPosition not scrolling to future sibling #14442

Merged
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
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