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

fix(module:datepicker): for not nullable - on clear set to defaults #1100

Merged

Conversation

anddrzejb
Copy link
Member

🤔 This is a ...

  • New feature
  • Bug fix
  • Site / documentation update
  • Demo update
  • Component style update
  • Bundle size optimization
  • Performance optimization
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Other (about what?)

💡 Background and solution

Due to the strongly typed nature of C#, DatePicker can get either nullable or not nullable dates. When not nullable are used, clearing the values was inputing min value for DateTime. There is not much we can do about (we can decide to take current date for example). This PR fixes the not nullable clearing scenario when defaults are set - in such case, date picker will assume defaults instead of DateTime.Min. For nullable the picker will be cleared.

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Changelog is provided or not needed

@ElderJames
Copy link
Member

I think it's more like a reset method..

@anddrzejb
Copy link
Member Author

Yes it is. Basically I retain the original functionality TValue is nullable. But if it is not, then we cannot clear it up - it will take default, which is minimum.
Without this change, if you specify:

<RangePicker TValue="DateTime[]" DefaultValue="@(new DateTime[] { DateTime.Now.AddYear(-1), DateTime.Now })" />

you will get this result
datepicker_Defaults

But I think it is better to set it back to defaults if they exist. Again, this is only if TValue is not nullable and defaults exist.

@ElderJames
Copy link
Member

What if the value is made minimum when cleared, and the input box is empty?

@anddrzejb
Copy link
Member Author

I guess this could be done, but I think this might send a wrong message to anyone consuming the date picker. So in this scenario, the date picker would show empty but the values (if @bind-Value="@values"), would have DateTime.Min. To be honest I wouldn't like a surprise like that in production.

@ElderJames
Copy link
Member

I'm not sure which is people's want.

@anddrzejb
Copy link
Member Author

Ok, I understand. I made this change because this is my use case and to me seemed most logical. Please remember that ppl will still have a choice - they will be able to empty completely the fields if they decide to choose DateTime?[] type for value. My scenario is only for DateTime[] and with DefaultValue existing.

@ElderJames ElderJames merged commit 3dc23bf into ant-design-blazor:master Feb 5, 2021
@anddrzejb
Copy link
Member Author

Wow, thanks 😄 that was faster than I anticipated.

@anddrzejb anddrzejb deleted the datePickerDefaultsOnReset branch February 9, 2021 18:22
ElderJames pushed a commit that referenced this pull request Apr 23, 2022
ElderJames pushed a commit that referenced this pull request Apr 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants