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): switching months in wheel picker now selected nearest neighbor #25559

Merged
merged 3 commits into from
Jun 30, 2022

Conversation

liamdebeasi
Copy link
Contributor

@liamdebeasi liamdebeasi commented Jun 29, 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: Internal ticket.

In #25422 (comment) it was discovered that switching months in the new preferWheel date picker would sometimes reset the selected day to 1.

This was happening when switching between months with different maximum days. For example, selecting May 31st then switching the month to April would cause the 1st to be selected. This is because there is no April 31st.

Under the hood, we were filtering the 31st out of the items passed into the picker column, and the picker column did not know what to do.

What is the new behavior?

  • When the items prop changes, the picker column will check to see if the selected item is still in the items array.
  • If it is, then it does nothing.
  • If the item is no longer available, it performs the following steps:
  1. Finds the location of the active item in the previous items array. If the index is not found, it returns early.
  2. If the index is found, it steps backwards through the current set of items, starting at the last known position of the selected item.
  3. For each item, it checks to see if a) the item is defined and b) the item is enabled. It breaks out of the loop if it finds an item that meets both criteria.
  4. If an item is found that meets the criteria, the value prop is updated and the nearest item is selected.
feature-6.2 branch
before.mov
after.mov

Does this introduce a breaking change?

  • Yes
  • No

Other information

@github-actions github-actions bot added the package: core @ionic/core package label Jun 29, 2022
@liamdebeasi liamdebeasi marked this pull request as ready for review June 29, 2022 18:06
@liamdebeasi liamdebeasi requested a review from a team as a code owner June 29, 2022 18:06
@sean-perkins
Copy link
Contributor

In your after example, when going from "March 29" to February, why does it activate "February 27" instead of the 28th?

@liamdebeasi
Copy link
Contributor Author

Good question! I should have simplified the example. There is an isDateEnabled callback that disables all even dates, so the 28th is never a selectable option. https://github.com/ionic-team/ionic-framework/blob/feature-6.2/core/src/components/datetime/test/prefer-wheel/index.html#L48-L53

Copy link
Contributor

@sean-perkins sean-perkins left a comment

Choose a reason for hiding this comment

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

Thanks for the added explanation, this looks good 👍

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.

3 participants