-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[pickers] Allow to define the default selected date in the view without setting a value #7500
Comments
Hi, On the version 5 of our package, you have to control the value (the On the version 6 of our package (currently in alpha), you have a new I hope it answers your question |
MobileDatePicker
Hey @flaviendelangle, in v5 the default focused day is the current day but the default date And if you provide a default value to change the default focused day, this would result in an unwanted side effects like the input having a default input instead of being empty. @sohaibnajjar I guess you can achieve a similar effect by overriding the default |
@Abdallatif if we are talking about the "focused date" as "the date with the pseudo-class You can decide which month to open when on the You could indeed do a custom solution using Reading the message of @sohaibnajjar, I thought he was talking about the selected value. |
Could you describe what you are trying to achieve in your application ? |
@flaviendelangle In the new date picker, there is no initialFocusedDate. Therefore, if the dialog is opened and "OK" is clicked without making a selection, the dialog will simply close and no value will be selected. An example of this behavior can be found on the Material-UI website: https://mui.com/x/react-date-pickers/date-picker/ Responsiveness => section => MobileDatePicker. We have implemented a hacky solution to mimic the old behavior, but we believe it is dangerous to continue using this method. What are your thoughts on this issue? A demo of this hacky solution can be found in this CodeSandbox link: https://codesandbox.io/s/priceless-wildflower-kggdgu?file=/demo.tsx:0-1259 |
OK so we are talking about the initial selected day inside the view. It is not equivalent to the focused day (in the sense of the browser focus) because you can focus a day with your keyboard without selecting it: In the image below, the selected day is You can use the In the meantime, your custom solution is not that hacky 👍 |
MobileDatePicker
Are any updates on this available? I am in need of setting a default month at the very least, but notice |
/**
* Default calendar month displayed when `value` and `defaultValue` are empty.
* @deprecated Consider using `referenceDate` instead.
*/
defaultCalendarMonth?: TDate; It weird, the deprecation warning contains the name of the new prop in the code, is this message not displayed on your IDE? You can find the doc about this new prop here |
@flaviendelangle Sorry for leaving this out, I have tried using |
All our props expects dates in the format of your date library ( |
@flaviendelangle I am not using a Date library, I was trying to use EDIT: I am using dayjs, I just forgot because I configured it a while ago |
@AlexWeinstein92 The issue here was that in the old date picker v-4 if you open the popup it will select the date by default then you can click But in the new date picker v-5 if you open the popup you need to select the date first you don't have something called default date we solved it by playing with some internal props like this.
In your case, I think they have a prop for the default month in v-5 it was |
To select a date by default, you can use |
The idea behind this logic is that I want the user to click ok to set the initial value not before, and if the user didn't click anything I want its value to stay empty. In your solution, the date picker will have a value in the first render. |
@sohaibnajjar that is a fair point. By setting It would be preferable to only have the value be set on click of the last view (month in my case) but alas it's not a big enough issue for me to worry about it at the moment |
Duplicates
Latest version
Summary 💡
when the "initialFocusedDate" is set to a specific day and the value is set to null, opening the date dialog and clicking "OK" without selecting a new value will result in the value being set to the "initialFocusedDate". However, if "Cancel" is clicked, the value will remain null.
We are talking about the initial selected day inside the view.
We could introduce a new
defaultSelectedValue
prop that defines thedraft
state.Examples 🌈
We have implemented a hacky solution to mimic the old behavior, but we believe it is dangerous to continue using this method. What are your thoughts on this issue? A demo of this hacky solution can be found in this CodeSandbox link: https://codesandbox.io/s/priceless-wildflower-kggdgu?file=/demo.tsx:0-1259
Motivation 🔦
we have a property called
initialFocusedDate
on the old version, I tried to use it and there is no property like that in the new MUI-X date pickers.The text was updated successfully, but these errors were encountered: