-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
DateRangePicker's controlled value can't be set to null to show the placeholder instead of the previous selected date #3187
Comments
Same issue here. The date range picker considers undefined value as a sign of an uncontrolled component and what's even weirder, seems to revert selection to the first selection ever made (e.g. if the user tries a few different options before attempting to reset the range altogether). Haven't tested a lot and setting the value to |
I guess export interface ValueBase<T, C = T> {
/** The current value (controlled). */
- value?: T,
+ value?: T | null,
/** The default value (uncontrolled). */
defaultValue?: T,
/** Handler that is called when the value changes. */
onChange?: (value: C) => void
} |
I'm trying to repro the issue with the latest version, here's the code sample -
Seems to me setting |
@lishichengyan do you have TS strict mode on? that can mess up some of these explicit vs implicit null's |
no, in tsconfig.json I see "strict": false, |
This issue appears to be related to granularity. If you set it to https://codesandbox.io/s/loving-christian-ciisig?file=/src/DateRangePicker.js
P.S also calling |
@lishichengyan if anything is unclear, please let me know |
Running into this as well, also without granularity set to minute. When setting the value to null, it doesn't reset the value and clear the segments. |
Apologies, I believe I misunderstood this issue the first time I looked at it, thought this was referring to a typescript strict mode issue. I've confirmed the issue where setting the date values to null isn't clearing the the visual range selected in the calendar dropdown when the granularity is set to "minute" or "second". EDIT: Did some quick digging, looks like we properly update the tracked controlled value in useDateRangeState but not the date range value. I believe we can just call |
I'm having the same issue with Does anyone have any workaround? |
I ended up having to |
@christofferok thanks, @christofferok - that's what I did too. 😞 |
As a workaround, I used diff --git a/src/inputs.d.ts b/src/inputs.d.ts
index 653b30af794558acb854a4fab593f514e8487d05..18e7ec3cf4d63537327f1f857c78a8f85ab16a02 100644
--- a/src/inputs.d.ts
+++ b/src/inputs.d.ts
@@ -33,7 +33,7 @@ export interface InputBase {
export interface ValueBase<T, C = T> {
/** The current value (controlled). */
- value?: T,
+ value?: T | null,
/** The default value (uncontrolled). */
defaultValue?: T,
/** Handler that is called when the value changes. */ You can use |
@devongovett This works great for setting value outside of the component itself. But referencing state from inside of the component doesn't allow for setting null on any of the values.
receives this error
I've tried bunch of combinations. Closest I got was
But this gives
Best way to reset value from internally using the state object returned by the hook? |
🐛 Bug Report
Value prop can't be set to null (as in the documentation) in DateRangePicker because TypeScript needs a DateValue type of value. Once the value prop has received a value then the value can't be removed completely from the date field to show just a placeholder again.
🤔 Expected Behavior
If the value prop in the DateRangePicker receives a null or undefined value then the previous selected date should be removed from the date field and should display a placeholder again instead of the previous selected date.
😯 Current Behavior
If the value prop in the DateRangePicker receives a null or undefined value then the previous selected date stays there in the date field.
🔦 Context
I am trying to reset the DateRangePicker's value to nothing to show the placeholder again after the previously selected date has been removed from the filtering list, so it makes less confusing for the users.
💻 Code Sample
🌍 Your Environment
🧢 Your Company/Team
AEM - Admin UI, Odin project
The text was updated successfully, but these errors were encountered: