-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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): reinit behavior on presentation change #24828
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, can we add E2E tests to verify this new behavior?
I am noticing the following error getting thrown during the E2E tests: TypeError: Cannot read properties of undefined (reading 'initializeCalendarIOListeners')
at initializeListeners (ion-datetime.entry.js:1659)
at Datetime.componentDidRender (ion-datetime.entry.js:1749)
at safeCall (index-765cc965.js:1580)
at postUpdateComponent (index-765cc965.js:1481)
at postUpdate (index-765cc965.js:1416) undefined Perhaps this is why the test is failing? |
I'm still working on it; there are a few different issues that need addressing. I'll re-request review when it's ready again. |
* purposes, e.g. to ensure month selection works. | ||
* @internal | ||
*/ | ||
@Event() ionWorkingPartsDidChange!: EventEmitter<DatetimeParts>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should replace the InitMonthDidChangeEvent
function completely. I'll make a separate PR to update the other tests once this has cleared review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way we can have a check that is only done in tests? My concern with this is that this extra code is only needed for tests but is now going to run in every production Ionic app that uses ion-datetime
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't able to find one, but I'm open to ideas. The old util (InitMonthDidChangeEvent
) fits the bill and uses a mutation observer to indirectly watch for the month to change, but it doesn't account for the month element being re-rendered (and thus the reference to the observed element being lost) when presentation
is changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spent some time exploring an alternative way to test this behavior. Here's a branch that shows how we can drop the internal event from ion-datetime
: https://github.com/ionic-team/ionic-framework/tree/test/FW-844.
It will apply a mutation observer to dispatch a custom event once the calendar body is manipulated. It will also re-attach the observer to the correct element node after the presentation is changed.
If you like this approach, feel free to take any parts of it/merge it into your working branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sean-perkins Thanks for that! I cleaned it up and brought it in 👍 cc @liamdebeasi
Alright, should finally be good to go now! Whew. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to go other than my one comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
Pull request checklist
Please check if your PR fulfills the following requirements:
npm run build
) was run locally and any changes were pushednpm run lint
) has passed locally and any fixes were made for failuresPull request type
Please check the type of change your PR introduces:
What is the current behavior?
When the
presentation
prop ondatetime
is changed programmatically, behaviors such as the intersection observers and keyboard listeners are disconnected.Issue URL: Resolves #24826
What is the new behavior?
calendarBodyRef
uses were updated to avoid being set tonull
due to a Stencil bug.Does this introduce a breaking change?
Other information