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

[CalendarPicker] Don't move to closest enabled date when props.date contains a disabled date #6537

Merged
merged 1 commit into from
Oct 17, 2022
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
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