Skip to content

Conversation

@averyjohnston
Copy link
Contributor

@averyjohnston averyjohnston commented Apr 12, 2023

What is the current behavior?

When using the dropdown month picker, the value is updated when the month is changed, to follow native behavior. However, because only the month is updated (the day remains the same), it's possible for the newly chosen date to fall outside the min/max bounds of the datetime.

For example, if you have a datetime with min="2021-01-15" value="2021-02-01", then use the month picker to switch to January, the new value will be 2021-01-01 which is earlier than the min.

Issue URL: Resolves #27027

What is the new behavior?

When updating the activeParts in any scenario, the date to set is now clamped between the max and min.

Does this introduce a breaking change?

  • Yes
  • No

Other information

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@github-actions github-actions bot added the package: core @ionic/core package label Apr 12, 2023
@averyjohnston averyjohnston marked this pull request as ready for review April 12, 2023 19:41
Copy link
Contributor

@liamdebeasi liamdebeasi left a comment

Choose a reason for hiding this comment

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

Would it make sense to clamp the date in setActiveParts instead? That would ensure that all dates set are guaranteed to be valid.

@sean-perkins
Copy link
Contributor

+1 to what Liam mentioned, I wonder if we can add this logic as part of the validateParts utility: https://github.com/ionic-team/ionic-framework/blob/main/core/src/components/datetime/utils/manipulation.ts#L338

@averyjohnston
Copy link
Contributor Author

Looks like that works!

@averyjohnston averyjohnston added this pull request to the merge queue Apr 18, 2023
Merged via the queue into main with commit 0385c08 Apr 18, 2023
@averyjohnston averyjohnston deleted the FW-3743 branch April 18, 2023 17:52
liamdebeasi pushed a commit that referenced this pull request Apr 19, 2023
…#27185)

<!-- Please refer to our contributing documentation for any questions on
submitting a pull request, or let us know here if you need any help:
https://ionicframework.com/docs/building/contributing -->

<!-- Some docs updates need to be made in the `ionic-docs` repo, in a
separate PR. See
https://github.com/ionic-team/ionic-framework/blob/main/.github/CONTRIBUTING.md#modifying-documentation
for details. -->

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

When using the dropdown month picker, the value is updated when the
month is changed, to follow native behavior. However, because only the
month is updated (the day remains the same), it's possible for the newly
chosen date to fall outside the min/max bounds of the datetime.

For example, if you have a datetime with `min="2021-01-15"
value="2021-02-01"`, then use the month picker to switch to January, the
new value will be `2021-01-01` which is earlier than the `min`.

<!-- Issues are required for both bug fixes and features. -->
Issue URL: Resolves #27027


## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

When updating the `activeParts` in any scenario, the date to set is now
clamped between the max and min.

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!-- If this introduces a breaking change, please describe the impact
and migration path for existing applications below. -->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->
@porojanmadalin
Copy link

porojanmadalin commented Mar 7, 2024

@averyjohnston
Copy link
Contributor Author

@madalinporojan2010 Please create a new issue with details: https://github.com/ionic-team/ionic-framework/issues/new/choose

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: ion-datetime does not clamp current date to min/max when switching months using month picker

5 participants