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

Block Library: Standardize reduced motion handling with media queries #68315

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from

Conversation

himanshupathak95
Copy link
Contributor

@himanshupathak95 himanshupathak95 commented Dec 26, 2024

Part of: #68282

What?

Refactors animation and transition styles to use @media not (prefers-reduced-motion) ensuring better accessibility for users who prefer reduced motion.

Why?

Currently, many places in the codebase do not account for user's motion preferences. This might not be correct for user's having reduced motion preferences. This PR fixes that.

Testing Instructions

  1. Open the Block Editor

  2. Add an Image block and upload an image

  3. Enable the lightbox feature in block settings

  4. Test normal behavior:

    • Click to open Lightbox
    • Observe opening/closing animations
    • Test zoom functionality
  5. Test with reduced motion preference:

    • Enable "Reduced motion" preference:
      • Chrome DevTools: Open DevTools > More Tools > Rendering > "Emulate CSS media feature prefers-reduced-motion" > select "reduce"
    • Repeat the above tests
    • Verify that:
      • Lightbox opens/closes without animation
      • No zoom animations occur
  6. Disable reduced motion and verify all original animations work correctly

Screencast

Image Block -

Screen.Recording.2024-12-26.at.15.53.49.mov

Navigation Block -

Screen.Recording.2024-12-31.at.08.52.32.mov

Social Links -

Screen.Recording.2024-12-31.at.08.58.58.mov

@himanshupathak95 himanshupathak95 marked this pull request as ready for review December 26, 2024 11:30
Copy link

github-actions bot commented Dec 26, 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: himanshupathak95 <[email protected]>
Co-authored-by: t-hamano <[email protected]>

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

@himanshupathak95
Copy link
Contributor Author

Hey @t-hamano!

Updated the animation handling to follow user preferences. Let me know if this is what you had in mind. Thanks!

@t-hamano t-hamano added [Type] Enhancement A suggestion for improvement. [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Package] Block library /packages/block-library labels Dec 27, 2024
Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Two pieces of feedback from me:

  • It would be better to use @media not ( prefers-reduced-motion ) instead of @media (prefers-reduced-motion: no-preference). See this comment. Furthermore, it would be good if you could update existing @media (prefers-reduced-motion: no-preference).
  • Does this PR only target the Image block? Or does it target the @wordpress/block-library? If it is the latter, it would be good to check other blocks as well.

@himanshupathak95
Copy link
Contributor Author

himanshupathak95 commented Dec 30, 2024

Hey @t-hamano, Thanks for the feedback.

Earlier I used @media not ( prefers-reduced-motion ) exactly like mentioned in the comment but the checks were all failing. Even in the local setup, I could see some warnings but the build was successful.
Reference -
https://github.com/WordPress/gutenberg/actions/runs/12502541314/job/34881643891
https://github.com/WordPress/gutenberg/actions/runs/12502541301/job/34881643107

This PR only targets the Image block but I can target the @wordpress/block-library if that is what you suggest.

@t-hamano
Copy link
Contributor

@himanshupathak95

After looking into the issue, it looks like we need to update sass version.

We may want to come back to this PR after progressing through #68380.

@t-hamano
Copy link
Contributor

@himanshupathak95

Now that I've merged #68380, could you rebase this PR? We should now be able to use @media not ( prefers-reduced-motion ).

Additionally, it may be a good idea to unify the following two formats:

@media (prefers-reduced-motion: no-preference) {

@media (prefers-reduced-motion: no-preference) {

This PR only targets the Image block but I can target the @wordpress/block-library if that is what you suggest.

Either is fine, but it's a good idea to make it clear in the PR title and description so that others can easily understand when they visit this PR later.

@himanshupathak95 himanshupathak95 changed the title A11y: Update animation/transition styles with reduced motion media queries Block Library: Standardize reduced motion handling with media queries Dec 31, 2024
@himanshupathak95
Copy link
Contributor Author

himanshupathak95 commented Dec 31, 2024

@t-hamano Thanks for merging #68380 in such a short time, the checks are passing now 🚀

I have made the changes as suggested, and I have also updated the PR title to reflect the changes. Please let me know if there is anything else I can do.

Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

I found two places where animations are not disabled even when "Reduced Motion" is enabled. Can you deal with these as well?

Image Lightbox: Hover animation on the toggle button and overlay animation when the lightbox is opened:

image.mp4

Navigation: Hover animation on a menu with child menus:

navigation.mp4

Comment on lines +144 to +146
@media not (prefers-reduced-motion) {
transition: box-shadow 0.2s ease-out;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The element to which this style is applied (.block-library-gallery-item__inline-menu) no longer exists, so it can be removed in a follow-up.

Comment on lines -83 to +86
transition: transform 0.1s ease;
@media not (prefers-reduced-motion) {
transition: transform 0.1s ease;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like a transition itself isn't needed here, because there is no animation applied to the a element.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Package] Block library /packages/block-library [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants