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(datetime): add correct null check when value changes #25716

Merged
merged 3 commits into from
Aug 5, 2022
Merged

Conversation

liamdebeasi
Copy link
Contributor

@liamdebeasi liamdebeasi commented Aug 4, 2022

Pull request checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
    • Some docs updates need to be made in the ionic-docs repo, in a separate PR. See the contributing guide for details.
  • Build (npm run build) was run locally and any changes were pushed
  • Lint (npm run lint) has passed locally and any fixes were made for failures

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Issue URL: resolves #25714

This fixes a regression caused by the multiple datetime PR. In particular, this line caused the bug: 81d0f3b#diff-4a407530c60e3cf72bcc11acdd21c4803a94bf47ea81b99e757db1c93d2735b8R344.

When defined, hour is a number. When the value prop changed and 12 AM was selected, hour was 0. This caused the ampm variable to be set to undefined because 0 is falsey. When the AM/PM picker column updated, it received undefined as the new value. Whenever the picker column re-renders, it checks to see what the active item is. In this case, it has no active item for value undefined, so it attempts to get itself back into a valid state by selecting the 0th item in the items array:

As a result, this causes the picker column to emit 'am' as the value again (since it is the 0th item in the items array). This causes the buggy code to run, forcing the ampm value back to undefined, causing the picker column to re-render again.

What is the new behavior?

  • Updated the relevant code to properly check for null or undefined values instead of falsey values.

Does this introduce a breaking change?

  • Yes
  • No

Other information

@github-actions github-actions bot added the package: core @ionic/core package label Aug 4, 2022
@liamdebeasi liamdebeasi marked this pull request as ready for review August 4, 2022 14:30
@liamdebeasi liamdebeasi requested a review from a team as a code owner August 4, 2022 14:30
@liamdebeasi liamdebeasi requested review from averyjohnston and sean-perkins and removed request for a team August 4, 2022 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: core @ionic/core package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: datetime picker in ion-modal crashes on selecting 12 AM
3 participants