Date range picker, end date controls forces you to re-enter start date
See original GitHub issueWhat package(s) are you using?
-
carbon-components
-
carbon-components-react
Detailed description
When you want to edit a selected date in the date range picker. Click on the end date control forces you to first re-enter the start date.
I believe that click on the end date control should only edit the end date.
The feature was tested under Chrome and Edge with the same behaviour.
Tested under Carbon Design System v10
Steps to reproduce the issue
- Select a start date and end date in the date range picker.
- Click on the end date field.
- Select a date.
Issue Analytics
- State:
- Created 4 years ago
- Comments:17 (9 by maintainers)
Top Results From Across the Web
Date Range Picker — JavaScript Date & Time Picker Library
A JavaScript component for choosing date ranges, dates and times. ... Originally created for reports at Improvely, the Date Range Picker can be...
Read more >When reset angular material date range picker event is always ...
Every form has clear button, that resets whole form value. In date range picker it is always displayed twice in console, in simple...
Read more >Start and end date validation - Power Platform Community
Hi,. ANy help with start and end time validation check please ? The validation logic doesnt re runs when datetime picker control's value...
Read more >Date range picker | U.S. Web Design System (USWDS)
A date range picker helps users select a range between two dates. Component preview. Event start date. mm/dd/yyyy.
Read more >How To Create a Password Validation Form - W3Schools
When the user starts to type something inside the password field myInput.onkeyup = function() { // Validate lowercase letters
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @abbeyhrt, that is indeed the issue. I ended up using a skeleton date picker until the date range is loaded, which solves the issue in the same way as your second example. Thanks so much for the help and the detailed response!
@JoelOtter Thank you for the sandbox, that was super helpful!
Looking through your sandbox, the problematic bit seemed to be the
selectedDateRange
state being initialized to an empty array and then being set to theinitialDateRange
in the effect, if you setselectedDateRange
like this:const [selectedDateRange, setSelectedDateRange] = useState([new Date(2022, 1, 10), new Date(2022, 5, 20)]);
and then removelet initialDateRange = [new Date(2022, 1, 10), new Date(2022, 5, 20)];
from the effect, the calendar then updates the dates as intended. Is there a reason that the initial stateselectedDateRange
needs to be set in an effect?Since
value
is being set in an effect, it happens too fast to see but DatePicker is first being rendered with that undefinedselectedDateRange
and then the effect runs andselectedDateRange
is updated to thatinitialDateRange
. In DatePicker,value
isn’t just the default prop, the component starts out with that value but it can be used at any time to force the date picker to be whatever range is in the value. Doing so changes the component to a “controlled” component which then overrides DatePicker’s own logic that it is using to update the dates and that’s why this issue is occurring.To avoid this issue, you could make the change I mentioned above sandbox example or, if state needs to be set in an effect, like say if that range is being fetched, then you can wait to render the dataPicker until that initialDateRange is set sandbox example for that.
Let me know if that makes sense or you have any more questions!