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

bug: datetime shows previous month after closing time popover #25438

Closed
4 of 7 tasks
TimGels opened this issue Jun 9, 2022 · 10 comments · Fixed by #25478
Closed
4 of 7 tasks

bug: datetime shows previous month after closing time popover #25438

TimGels opened this issue Jun 9, 2022 · 10 comments · Fixed by #25478
Labels
package: core @ionic/core package type: bug a confirmed bug report

Comments

@TimGels
Copy link

TimGels commented Jun 9, 2022

Prerequisites

Ionic Framework Version

  • v4.x
  • v5.x
  • v6.x
  • Nightly

Current Behavior

I find this issue a bit difficult to describe, as I don't know what some parts of the date-time element are called. But I will embed a video.

When selecting a time using the date-time element, the calendar will be shown in an incorrect state. Or at least, it seems like it tries to show May instead of the current (by the time of this issue) June.

Before selecting a time:
afbeelding

After selecting a time:
afbeelding

Expected Behavior

After selecting a time, I do not expect the day to get changed (when a day is selected). When no day is selected, I expect it to select a default date or today's date after selecting a time, or at the very least not a "jumping" calendar.

It does seem to work when selecting a day from another month before selecting a time.

2022-06-09.10-36-06.mp4

Steps to Reproduce

  1. Select a time
  2. Dismiss the popover time scroll wheel by clicking the backdrop
  3. The calendar will show incorrectly
2022-06-09.10-10-13.mp4

  1. Select a day in the same month that is open
  2. Select a time
  3. Dismiss the popover time scroll wheel by clicking the backdrop
  4. The calendar will be shown incorrectly
2022-06-09.10-10-57.mp4

Code Reproduction URL

https://github.com/TimGels/ionic-date-time-repro

Ionic Info

[WARN] Error loading @capacitor/ios package.json: Error: Cannot find module '@capacitor/ios/package'

       Require stack:
       - C:\Users\user\AppData\Roaming\npm\node_modules\@ionic\cli\lib\project\index.js
       - C:\Users\user\AppData\Roaming\npm\node_modules\@ionic\cli\lib\index.js
       - C:\Users\user\AppData\Roaming\npm\node_modules\@ionic\cli\index.js
       - C:\Users\user\AppData\Roaming\npm\node_modules\@ionic\cli\bin\ionic
[WARN] Error loading @capacitor/android package.json: Error: Cannot find module '@capacitor/android/package'

       Require stack:
       - C:\Users\user\AppData\Roaming\npm\node_modules\@ionic\cli\lib\project\index.js
       - C:\Users\user\AppData\Roaming\npm\node_modules\@ionic\cli\lib\index.js
       - C:\Users\user\AppData\Roaming\npm\node_modules\@ionic\cli\index.js
PS C:\Users\user\projects\ionic-date-time-repro\ionic-date-time-repro> ionic info
[WARN] Error loading @capacitor/ios package.json: Error: Cannot find module '@capacitor/ios/package'

       Require stack:
       - C:\Users\user\AppData\Roaming\npm\node_modules\@ionic\cli\lib\project\index.js
       - C:\Users\user\AppData\Roaming\npm\node_modules\@ionic\cli\lib\index.js
       - C:\Users\user\AppData\Roaming\npm\node_modules\@ionic\cli\index.js
       - C:\Users\user\AppData\Roaming\npm\node_modules\@ionic\cli\bin\ionic
[WARN] Error loading @capacitor/android package.json: Error: Cannot find module '@capacitor/android/package'

       Require stack:
       - C:\Users\user\AppData\Roaming\npm\node_modules\@ionic\cli\lib\project\index.js
       - C:\Users\user\AppData\Roaming\npm\node_modules\@ionic\cli\lib\index.js
       - C:\Users\user\AppData\Roaming\npm\node_modules\@ionic\cli\index.js
       - C:\Users\user\AppData\Roaming\npm\node_modules\@ionic\cli\bin\ionic

Ionic:

   Ionic CLI                     : 6.18.2 (C:\Users\user\AppData\Roaming\npm\node_modules\@ionic\cli)
   Ionic Framework               : @ionic/angular 6.1.9
   @angular-devkit/build-angular : 14.0.1
   @angular-devkit/schematics    : 14.0.1
   @angular/cli                  : 14.0.1
   @ionic/angular-toolkit        : 6.1.0

Capacitor:

   Capacitor CLI      : 3.5.1
   @capacitor/android : not installed
   @capacitor/core    : 3.5.1
   @capacitor/ios     : not installed

Utility:

   cordova-res : not installed globally
   native-run  : 1.6.0

System:

   NodeJS : v16.14.0 (C:\Program Files\nodejs\node.exe)
   npm    : 8.3.1
   OS     : Windows 10

Additional Information

N/A

@ionitron-bot ionitron-bot bot added the triage label Jun 9, 2022
@TimGels
Copy link
Author

TimGels commented Jun 9, 2022

It looks to me that this issue is not present in the time-date presentation.

2022-06-09.11-00-34.mp4

@liamdebeasi
Copy link
Contributor

Thanks for the issue. What browser are you testing this on?

@liamdebeasi liamdebeasi added the needs: reply the issue needs a response from the user label Jun 9, 2022
@ionitron-bot ionitron-bot bot removed the triage label Jun 9, 2022
@TimGels
Copy link
Author

TimGels commented Jun 9, 2022

I am testing this on Firefox v101.0. I have also reproduced the issue on Chrome v102.0.5005.63

@ionitron-bot ionitron-bot bot added triage and removed needs: reply the issue needs a response from the user labels Jun 9, 2022
@liamdebeasi liamdebeasi self-assigned this Jun 15, 2022
@liamdebeasi
Copy link
Contributor

liamdebeasi commented Jun 15, 2022

Thanks, I can reproduce this. When overlays in Ionic dismiss, we automatically bring focus back to the previously focused element: https://github.com/ionic-team/ionic-framework/blob/main/core/src/utils/overlays.ts#L448 If we did not do this, the focus gets set to the body and keyboard users will need to re-tab back to where they were before opening the overlay.

The time picker is presented in a popover, one of the overlay types in Ionic. When the popover dismisses, we grab the first focusable element inside of ion-datetime and focus it. In this case, we are focusing the first button in the previous month. In Chrome and Firefox, focusing an out of view element causes the element to scroll into view. This results in the behavior reported here.


This function should never grab the first button because the calendar grid container is focusable: https://github.com/ionic-team/ionic-framework/blob/main/core/src/components/datetime/datetime.tsx#L1497 (This is how we capture focus so users can use the arrow keys to navigate in the calendar grid). The query selector we use in focusPreviousElementOnDismiss never considers .ion-focused. It probably should as the other query selector we use considers .ion-focused. (We should also consider just merging these two variables).

edit: This bug only happens when there is no value set.

@liamdebeasi liamdebeasi changed the title bug: date-time element showing incorrectly after selecting a time bug: datetime shows previous month after closing time popover Jun 15, 2022
@liamdebeasi liamdebeasi added package: core @ionic/core package type: bug a confirmed bug report labels Jun 15, 2022
@liamdebeasi
Copy link
Contributor

Can you try the following dev build and let me know if it resolves the issue?

npm install @ionic/angular@6.1.11-dev.11655311674.153c1bea

@liamdebeasi liamdebeasi removed their assignment Jun 15, 2022
@liamdebeasi liamdebeasi mentioned this issue Jun 15, 2022
7 tasks
@TimGels
Copy link
Author

TimGels commented Jun 17, 2022

I installed @ionic/angular@6.1.11-dev.11655311674.153c1bea but the issue is still present.

@liamdebeasi
Copy link
Contributor

liamdebeasi commented Jun 17, 2022

What is the output of running ionic info from your project's directory? I tested your GitHub repo in Firefox and Chrome with the dev build and things appear to be working now.

@TimGels
Copy link
Author

TimGels commented Jun 17, 2022

What is the output of running ionic info from your project's directory? I tested your GitHub repo in Firefox and Chrome with the dev build and things appear to be working now.

My apologies, it appears that I had installed the @ionic/angular package in the wrong directory. Now that I installed it in the correct project, it is indeed fixed!

@liamdebeasi
Copy link
Contributor

Thanks for the issue. This has been resolved via #25478, and a fix will be available in an upcoming release of Ionic Framework.

@ionitron-bot
Copy link

ionitron-bot bot commented Jul 17, 2022

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Jul 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
package: core @ionic/core package type: bug a confirmed bug report
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants