Skip to content

Commit

Permalink
[CalendarPicker] Don't move to closest enabled date when props.date
Browse files Browse the repository at this point in the history
… contains a disabled date (#6537)
  • Loading branch information
flaviendelangle authored Oct 17, 2022
1 parent cf43507 commit 3f3053d
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 34 deletions.
16 changes: 0 additions & 16 deletions packages/x-date-pickers/src/CalendarPicker/CalendarPicker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,22 +160,6 @@ describe('<CalendarPicker />', () => {
});
});

it('should select the closest enabled date if the prop.date contains a disabled date', () => {
const onChange = spy();

render(
<CalendarPicker
date={adapterToUse.date(new Date(2019, 0, 1))}
onChange={onChange}
maxDate={adapterToUse.date(new Date(2018, 0, 1))}
/>,
);

// onChange must be dispatched with newly selected date
expect(onChange.callCount).to.equal(React.version.startsWith('18') ? 2 : 1); // Strict Effects run mount effects twice
expect(onChange.lastCall.args[0]).toEqualDateTime(new Date(2018, 0, 1));
});

describe('view: day', () => {
it('renders day calendar standalone', () => {
render(<CalendarPicker date={adapterToUse.date(new Date(2019, 0, 1))} onChange={() => {}} />);
Expand Down
18 changes: 0 additions & 18 deletions packages/x-date-pickers/src/CalendarPicker/CalendarPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -374,24 +374,6 @@ export const CalendarPicker = React.forwardRef(function CalendarPicker<TDate>(
[utils, date, onChange],
);

React.useEffect(() => {
if (date && isDateDisabled(date)) {
const closestEnabledDate = findClosestEnabledDate({
utils,
date,
minDate,
maxDate,
disablePast,
disableFuture,
isDateDisabled,
});

onChange(closestEnabledDate, 'partial');
}
// This call is too expensive to run it on each prop change.
// So just ensure that we are not rendering disabled as selected on mount.
}, []); // eslint-disable-line

React.useEffect(() => {
if (date) {
changeMonth(date);
Expand Down

0 comments on commit 3f3053d

Please sign in to comment.