Skip to content

Commit

Permalink
[DateRangePicker] Fix currentMonthCalendarPosition prop behavior on…
Browse files Browse the repository at this point in the history
… mobile
  • Loading branch information
LukasTy committed Feb 4, 2025
1 parent b252b9a commit 3bb8560
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ const MobileDateRangePicker = React.forwardRef(function MobileDateRangePicker<
format: utils.formats.keyboardDate,
// Force one calendar on mobile to avoid layout issues
calendars: 1,
// force current calendar position, since we only have one calendar
currentMonthCalendarPosition: 1,
views: ['day'] as const,
openTo: 'day' as const,
slots: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { DateRange } from '@mui/x-date-pickers-pro/models';
import { PickerValidDate } from '@mui/x-date-pickers/models';
import { SingleInputDateRangeField } from '@mui/x-date-pickers-pro/SingleInputDateRangeField';

describe('<MobileDateRangePicker />', () => {
describe.only('<MobileDateRangePicker />', () => {
const { render } = createPickerRenderer({ clock: 'fake' });

describe('Field slot: SingleInputDateRangeField', () => {
Expand Down Expand Up @@ -291,6 +291,22 @@ describe('<MobileDateRangePicker />', () => {
});
});

it('should ignore "currentMonthCalendarPosition" prop value and have expected selection behavior', () => {
render(
<MobileDateRangePicker
currentMonthCalendarPosition={2}
open
referenceDate={adapterToUse.date('2022-04-17')}
/>,
);

fireEvent.click(screen.getByRole('gridcell', { name: '3' }));
fireEvent.click(screen.getByRole('gridcell', { name: '5' }));

expect(screen.getByText('Apr 3')).not.to.equal(null);
expect(screen.getByText('Apr 5')).not.to.equal(null);
});

// TODO: Write test
// it('should call onClose and onAccept with the live value when clicking outside of the picker', () => {
// })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ const MobileDateTimeRangePicker = React.forwardRef(function MobileDateTimeRangeP
calendars: 1,
// force true to correctly handle `renderTimeViewClock` as a renderer
ampmInClock: true,
// force current calendar position, since we only have one calendar
currentMonthCalendarPosition: 1,
slots: {
field: MultiInputDateTimeRangeField,
...defaultizedProps.slots,
Expand Down

0 comments on commit 3bb8560

Please sign in to comment.