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(date-picker): stabilize defaultDate behavior #13186

Conversation

francinelucca
Copy link
Collaborator

@francinelucca francinelucca commented Feb 17, 2023

Closes #13058

  • Ignore time in date objects when comparing for equality to prevent overrides
  • clear input values on re-render when value prop is set to prevent overrides
  • Add test story (to be deleted)

Why

Issue here was with the introduction of hasInput the calendar instance is being destroyed and recreated the first time the components loads; so when a default value is set and the calendar instance was destroyed after the inputs had been populated (with the default values), it was picking up the dates both from the input fields and the defaultDate value, causing the flatpickr instance to behave unexpectedly.

Upon fixing that, found another issue where attempting to change the date through the calendar when a defaultValue had been previously set required the user to double click on the date due to the first click being overriden by a date equality comparison that didn't evaluate to true due to digressing times on the date resulting from a date object being created from the defaultValue VS creating it from the calendar selection.

Changelog

Changed

  • packages/react/src/components/DatePicker/DatePicker.js: clear input values on re-render when value prop is set to prevent overrides
  • packages/react/src/components/DatePicker/plugins/fixEventsPlugin.js: Ignore time in date objects when comparing for equality to prevent overrides

Testing / Reviewing

Test using "test" story in Datepicker in deployment

TODO

  • Delete test story

* Ignore time in date objects when comparing for equality to prevent overrides
* clear input values on rerender when value prop is set to prevent overrides
* Add test story (to be deleted)
@netlify
Copy link

netlify bot commented Feb 17, 2023

Deploy Preview for carbon-components-react ready!

Name Link
🔨 Latest commit 2a99860
🔍 Latest deploy log https://app.netlify.com/sites/carbon-components-react/deploys/63f8e69907cdd9000747eaa7
😎 Deploy Preview https://deploy-preview-13186--carbon-components-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Feb 17, 2023

Deploy Preview for carbon-elements ready!

Name Link
🔨 Latest commit 4fddf22
🔍 Latest deploy log https://app.netlify.com/sites/carbon-elements/deploys/63f7d219a24ae6000893a8ef
😎 Deploy Preview https://deploy-preview-13186--carbon-elements.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Copy link
Member

@tay1orjones tay1orjones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Behaves as expected for me in the test storybook! 👍

Copy link
Member

@tw15egan tw15egan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working as expected! Nice work on this 🎉 ✅ 👍🏻

@francinelucca francinelucca changed the title DO NOT MERGE - fix(date-picker): stabilize defaultDate behavior fix(date-picker): stabilize defaultDate behavior Feb 23, 2023
@kodiakhq kodiakhq bot merged commit 2ca3000 into carbon-design-system:main Feb 24, 2023
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.

[Bug]: DatePicker with initial value
4 participants