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

Popover: set is-positioned class only after animation has finished #54178

Merged
merged 5 commits into from
Sep 5, 2023

Conversation

jsnajdr
Copy link
Member

@jsnajdr jsnajdr commented Sep 5, 2023

This should be the ultimate fix for the flaky popover tests (like DotTip) that @ramonjd has been trying to fix in #54168. The snapshot differences are caused by the fact that the popover's Framer Motion animation is still running when we are checking the snapshot, and the animated style properties like opacity or translateY have non-deterministic values.

The fix is to set the is-positioned CSS class on the popover element only after the animation is complete. Then the .toBePositionedPopover Jest helper will reliably wait for the animation to finish.

To achieve this, I first had to merge the AnimationWrapper component into the base UnforwardedPopover component. Their internals need to communicate with each other now, and the separation is no longer tenable.

After merging, it's easy to introduce a finishedAnimation state variable, set by the Framer Motion's onAnimationComplete callback, and use finishedAnimation as another pre-condition for is-positioned.

We've discussed this a year ago with @ciampo and @tyxla, but at the time merging the AnimationWrapper was too hard. Today, after many incremental refactorings, it's possible.

Note that the updated DotTip snapshot now correctly reflects the "animation complete" state: opacity is 1, i.e., element is fully visible, and there are no translate and scale transforms.

@jsnajdr jsnajdr added [Type] Bug An existing feature does not function as intended [Package] Components /packages/components labels Sep 5, 2023
@jsnajdr jsnajdr self-assigned this Sep 5, 2023
Copy link
Contributor

@ciampo ciampo left a comment

Choose a reason for hiding this comment

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

Nice and clean, and also well explained in the PR description. Thank you!

LGTM 🚀

@@ -8,7 +8,8 @@

### Enhancements
Copy link
Contributor

Choose a reason for hiding this comment

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

Not related to this PR, but I noticed that the Enhancements header is not rendering as expected because (I believe) of a different space character than the normal one. Would you mind fixing that in this PR too? Thank you!

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, there was a Unicode no-break space character there (C2A0 in UTF-8) 👍

@@ -8,7 +8,8 @@

### Enhancements

- Making Circular Option Picker a `listbox`. Note that while this changes some public API, new props are optional, and currently have default values; this will change in another patch. ([#52255](https://github.com/WordPress/gutenberg/pull/52255))
- Making Circular Option Picker a `listbox`. Note that while this changes some public API, new props are optional, and currently have default values; this will change in another patch ([#52255](https://github.com/WordPress/gutenberg/pull/52255)).
- `Popover`: Add the `is-positioned` CSS class only after the popover has finished animating ([54178](https://github.com/WordPress/gutenberg/pull/54178)).
Copy link
Contributor

Choose a reason for hiding this comment

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

A missing # could maybe be the reason why the CI check is failing?

Suggested change
- `Popover`: Add the `is-positioned` CSS class only after the popover has finished animating ([54178](https://github.com/WordPress/gutenberg/pull/54178)).
- `Popover`: Add the `is-positioned` CSS class only after the popover has finished animating ([#54178](https://github.com/WordPress/gutenberg/pull/54178)).

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed!

@jsnajdr jsnajdr enabled auto-merge (squash) September 5, 2023 10:14
Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

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

A logical fix. Thank you, @jsnajdr!

@jsnajdr jsnajdr merged commit bafaa37 into trunk Sep 5, 2023
@jsnajdr jsnajdr deleted the update/popover-wait-animation branch September 5, 2023 10:42
@github-actions github-actions bot added this to the Gutenberg 16.7 milestone Sep 5, 2023
@ramonjd
Copy link
Member

ramonjd commented Sep 5, 2023

Thank you for following this up @jsnajdr!! 🙇🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants