question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Date range picker, end date controls forces you to re-enter start date

See original GitHub issue

What 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

  1. Select a start date and end date in the date range picker.
  2. Click on the end date field.
  3. Select a date.

image

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:17 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
JoelOttercommented, Jun 24, 2022

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!

0reactions
abbeyhrtcommented, Jun 23, 2022

@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 the initialDateRange in the effect, if you set selectedDateRange like this: const [selectedDateRange, setSelectedDateRange] = useState([new Date(2022, 1, 10), new Date(2022, 5, 20)]); and then remove let 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 state selectedDateRange 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 undefined selectedDateRange and then the effect runs and selectedDateRange is updated to that initialDateRange. 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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found