Skip to content

fix(datetime): clamp date between min and max when using month picker - #27185

Merged
averyrousseau merged 3 commits into
mainfrom
FW-3743
Apr 18, 2023
Merged

averyrousseau merged 3 commits into
mainfrom
FW-3743

Conversation

@averyrousseau

@averyrousseau averyrousseau commented Apr 12, 2023 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown

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
@averyrousseau
averyrousseau marked this pull request as ready for review April 12, 2023 19:41

@liamdebeasi liamdebeasi left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

@averyrousseau

Copy link
Copy Markdown
Contributor Author

Looks like that works!

@averyrousseau
averyrousseau added this pull request to the merge queue Apr 18, 2023
Merged via the queue into main with commit 0385c08 Apr 18, 2023
@averyrousseau
averyrousseau 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

porojanmadalin commented Mar 7, 2024 •

Copy link
Copy Markdown

@averyrousseau

Copy link
Copy Markdown
Contributor Author

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

4 participants