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

DateInput defaultDate prop does not work when value={null} #4426

Open
tofu2323 opened this issue Jun 20, 2023 · 4 comments
Open

DateInput defaultDate prop does not work when value={null} #4426

tofu2323 opened this issue Jun 20, 2023 · 4 comments
Labels
help wanted Contributions from community are welcome

Comments

@tofu2323
Copy link

What package has an issue

@mantine/dates

Describe the bug

The defaultDate prop does not work on DateInput with useForm

What version of @mantine/hooks page do you have in package.json?

6.0.13

If possible, please include a link to a codesandbox with the reproduced problem

https://codesandbox.io/s/objective-lichterman-4qy3ml?file=/src/App.tsx

Do you know how to fix the issue

No

Are you willing to participate in fixing this issue and create a pull request with the fix

None

Possible fix

No response

@rtivital rtivital changed the title defaultDate prop does not work on DateInput with useForm DateInput defaultDate prop does not work when value={null} Jun 20, 2023
@rtivital rtivital added the help wanted Contributions from community are welcome label Jun 20, 2023
@AdamGEmerson
Copy link

I'd like to take a stab at this if no one else is already working on it.

@cyantree
Copy link
Contributor

@rtivital For DateInput what's the difference between defaultDate and defaultValue and between date and value.

@tofu2323 Why do you need defaultDate? Have you tried using the date in initialValues instead?
Is it so that the field falls back to a specific date in case it has no value (or its value gets cleared)?

@AdamGEmerson Feel free to do so. :) I just had a quick look into the code but had difficulties understanding the meaning of the various props (see my question to rtivital).

@cyantree
Copy link
Contributor

Also the docs say that defaultDate and defaultValue are meant for uncontrolled use which isn't the case with useForm().
https://mantine.dev/dates/date-input/?t=props
https://mantine.dev/dates/date-picker-input/?t=props

@AdamGEmerson
Copy link

As @cyantree stated, the most likely issue is that these props are meant for uncontrolled input and useForm is controlled.

I also noticed playing with the example sandbox that the DatePicker component isn't "working" either. The defaultDate prop will continue to overwrite the input value even after form.getInputProps() is called with a valid Date set in initialValues.

See this example:
Code Sandbox

One thing that might be worth addressing here is why the DateInput and DatePickerInput behave differently in this scenario. DatePickerInput responds with "Invalid Date", and DateInput just displays as empty. Is this expected behavior?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Contributions from community are welcome
Projects
None yet
Development

No branches or pull requests

4 participants