mui / mui-x

MUI X: Build complex and data-rich applications using a growing list of advanced React components, like the Data Grid, Date and Time Pickers, Charts, and more!
https://mui.com/x/
3.82k stars 1.14k forks source link

[pickers][DatePicker] Allow same date to be selected with `onChange` event fired #12903

Open AgrYpn1a opened 3 weeks ago

AgrYpn1a commented 3 weeks ago

Summary

I am using a StaticDatePIcker in a custom dropdown menu which needs to be closed after the day has been selected. I am using onChange to detect that selection, however, if I press on the same day (which is still a valid use case, because I want to confirm that I want to use the already selected day) the onChange is not triggered.

I saw that there used to be a prop called allowSameDateSelection that allows for that behaviour but for some reason it is removed. Is there any other way to achieve this without customising the days renderer or similar?

Examples

No response

Motivation

No response

Search keywords: static date picker

michelengelen commented 3 weeks ago

Well, technically this is correct behaviour, since the value does not change. @LukasTy can we provide a different "point of entry" for this? Maybe with slotProps.day.onDaySelect?

AgrYpn1a commented 2 weeks ago

@michelengelen Thanks for the fast response, indeed it is, but I still need a way to detect that user has clicked on that day in the calendar.

michelengelen commented 2 weeks ago

That's where @LukasTy could be of help. 👍🏼

codemasterblackperl commented 2 weeks ago

@michelengelen as @AgrYpn1a mentioned, in v5 pickers we can detect same-day selection. We built our scheduling system based on this behavior. Same-day selection provided the toggling functionality. The toggling functionality broke when we tried to update the x-date pickers to v6 because it is no longer firing the selected day if you click on it again.

It would be great to have this function back

michelengelen commented 2 weeks ago

OK, I will add this to the board. 👍🏼

I do not think that we might want to fire an onChange as technically the value did not change, but we are likely to find another solution for this.