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

ToggleGroupControl: improve animation #65175

Merged
merged 55 commits into from
Oct 1, 2024

Conversation

DaniGuardiola
Copy link
Contributor

@DaniGuardiola DaniGuardiola commented Sep 10, 2024

(#64926 needs to merge first)

What?

Replaced framer motion based animation with a faster CSS animation similar to the work already done in Tabs (see #64926 for latest update there).

Why?

Faster and more lightweight, also see #60975

How?

Implement similar animation to Tabs, with the main difference being that instead of being transform-based, it is left + width based since that retains appropriate border radius dimensions.

Testing Instructions

Try the component in the Storybook or in Gutenberg (e.g. in the block inspector with a paragraph selected -> "Typography - SIZE").

Testing Instructions for Keyboard

Try the component with a keyboard.

Screenshots or screencast

Looks exactly the same as before, possibly feels a bit more snappy though it's hard to tell.

Kapture.2024-09-10.at.03.11.54.mp4

Copy link

github-actions bot commented Sep 10, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: DaniGuardiola <daniguardiola@git.wordpress.org>
Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@DaniGuardiola DaniGuardiola self-assigned this Sep 10, 2024
@DaniGuardiola DaniGuardiola added [Type] Enhancement A suggestion for improvement. [Package] Components /packages/components labels Sep 10, 2024
@DaniGuardiola DaniGuardiola requested review from a team and t-hamano September 10, 2024 01:14
@mirka
Copy link
Member

mirka commented Sep 10, 2024

I'm done for the day so I haven't reviewed yet, but noting that this is also a bug fix for animation issues like this ✨

CleanShot.2024-09-10.at.23.02.29.mp4

(Seen in the Query block when "Inner blocks use content width" is enabled.)

@DaniGuardiola
Copy link
Contributor Author

@mirka nice! I didn't know about that bug, glad to learn that it is fixed by this :)

@DaniGuardiola
Copy link
Contributor Author

Heads up, I've DRYed it up a bit by moving the animation code into a useSubelementAnimation hook for simplicity and because we could reuse this in the Tabs animation to de-duplicate the logic (in a follow-up).

@ciampo
Copy link
Contributor

ciampo commented Sep 30, 2024

The transition feels snappier, and I think that the border radius math is working well!

Although it looks like the deselectable version of the component has a visual bug when un-selecting an option item:

Kapture.2024-09-30.at.19.05.04.mp4

It's also probably better to incorporate changes from #64371 , since it introduces tweaks to packages/components/src/utils/element-rect.ts. We can do a final round of review then

@DaniGuardiola
Copy link
Contributor Author

@ciampo found the cause, works as expected now. Also, that PR merged and I synced here. Did one final round of testing, all looks good on my side. Final review?

baseId,
isBlock: ! isAdaptiveWidth,
size,
// @ts-expect-error - This is wrong and we should fix it.
Copy link
Contributor

Choose a reason for hiding this comment

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

This mismatch between null and undefined as possible value types was already there prior to this PR, and it sounds like something we should solve — cc @mirka , could this be part of the work you're intending to do about fixing ToggleGroupControl's focus bug?

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.

I pushed a couple of commits to remove merge conflicts, fix snapshots and make sure that I was testing on top of latest trunk.

I couldn't find any bugs or regressions, and the animation definitely feels smoother with the recent change to using transform.

I left a couple of comments, but they're small stuff and this PR can be merged once they are addressed

LGTM 🚀

@DaniGuardiola DaniGuardiola enabled auto-merge (squash) October 1, 2024 14:46
@DaniGuardiola DaniGuardiola merged commit 249f701 into trunk Oct 1, 2024
63 checks passed
@DaniGuardiola DaniGuardiola deleted the improve/toggle-group-control-animation branch October 1, 2024 17:04
@github-actions github-actions bot added this to the Gutenberg 19.4 milestone Oct 1, 2024
huubl pushed a commit to huubl/gutenberg that referenced this pull request Oct 2, 2024
* Refactor utils and switch Tabs indicator animation to `transform`.

* docs tweak

* Update packages/components/src/tabs/styles.ts

Co-authored-by: Marco Ciampini <marco.ciampo@gmail.com>

* Add RTL support.

* Addressed @ciampo's comments.

* Correct for antialiasing rounding.

* Make antialiasing adjustment optional.

* Use larger base value and revert antialiasing adjustment code.

* DRY RTL

* Remove RTL story (redundant since Storybook has a dynamic setting to test RTL).

* Fix bug.

* Fix bug (for real this time).

* Add changelog entry.

* De-cleverfy code.

* Sync useResizeObserver with WordPress#64943 and make useTrackElementOffsetRect resilient.

* Deduplicate utility and clean up.

* Minor Tabs code improvement.

* Replace framer motion animation with faster CSS animation.

* DRY antialiasing factor.

* Changelogs.

* Various improvements, fixes, and feedback addressed.

* Simplify.

* Simplify using derived state.

* Add similar useOnValueUpdate detail to Tabs.

* Fix skipping animation.

* Add similar detail to Tabs animation.

* Fix setState depth issue.

* Fix unit test error.

* Add changelog entries

* Fix changelog

* Update test snapshot.

* Depends less on React.

* Switch to layout effect for `useOnValueUpdate`

* Switched to transform strategy.

* Fix resizing bug.

* Transition border-radius too.

* Undo Tabs changes (no longer relevant).

* DRY animation code.

* Avoid useless re-runs in effect.

* Rename `activeElement` -> `selectedElement` for clarity.

* Rename `--indicator-` -> `--selected-` for accuracy.

* Minor tweak.

* Add safe defaults to CSS custom properties.

* Tweak `useSubelementAnimation`.

* Fix parent missing when there's no selected option.

* Update snapshots

* Add docs to utility.

* Added note about border-radius.

---------

Co-authored-by: Marco Ciampini <marco.ciampo@gmail.com>
Co-authored-by: DaniGuardiola <daniguardiola@git.wordpress.org>
Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
huubl added a commit to huubl/gutenberg that referenced this pull request Oct 2, 2024
draganescu pushed a commit that referenced this pull request Oct 2, 2024
* Refactor utils and switch Tabs indicator animation to `transform`.

* docs tweak

* Update packages/components/src/tabs/styles.ts

Co-authored-by: Marco Ciampini <marco.ciampo@gmail.com>

* Add RTL support.

* Addressed @ciampo's comments.

* Correct for antialiasing rounding.

* Make antialiasing adjustment optional.

* Use larger base value and revert antialiasing adjustment code.

* DRY RTL

* Remove RTL story (redundant since Storybook has a dynamic setting to test RTL).

* Fix bug.

* Fix bug (for real this time).

* Add changelog entry.

* De-cleverfy code.

* Sync useResizeObserver with #64943 and make useTrackElementOffsetRect resilient.

* Deduplicate utility and clean up.

* Minor Tabs code improvement.

* Replace framer motion animation with faster CSS animation.

* DRY antialiasing factor.

* Changelogs.

* Various improvements, fixes, and feedback addressed.

* Simplify.

* Simplify using derived state.

* Add similar useOnValueUpdate detail to Tabs.

* Fix skipping animation.

* Add similar detail to Tabs animation.

* Fix setState depth issue.

* Fix unit test error.

* Add changelog entries

* Fix changelog

* Update test snapshot.

* Depends less on React.

* Switch to layout effect for `useOnValueUpdate`

* Switched to transform strategy.

* Fix resizing bug.

* Transition border-radius too.

* Undo Tabs changes (no longer relevant).

* DRY animation code.

* Avoid useless re-runs in effect.

* Rename `activeElement` -> `selectedElement` for clarity.

* Rename `--indicator-` -> `--selected-` for accuracy.

* Minor tweak.

* Add safe defaults to CSS custom properties.

* Tweak `useSubelementAnimation`.

* Fix parent missing when there's no selected option.

* Update snapshots

* Add docs to utility.

* Added note about border-radius.

---------

Co-authored-by: Marco Ciampini <marco.ciampo@gmail.com>
Co-authored-by: DaniGuardiola <daniguardiola@git.wordpress.org>
Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants