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

USWDS - Core: Add transition utility with reduced motion preference handling #6268

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

Conversation

aduth
Copy link
Contributor

@aduth aduth commented Dec 20, 2024

Summary

Animated transitions now respect the system's reduced motion preference. A new transition utility handles default behavior for easing and disabling inessential animation.

Breaking change

This is not a breaking change.

Related issue

Closes #5256

Preview link

In local Storybook, can be previewed at:

Problem statement

As a user who may be distracted or experience harm such as nausea due to animated content, I expect that the U.S. Web Design System will respect my preference to experience reduced motion where possible.

Related:

Solution

Adds a new utility u-transition with smart defaults to handle:

  • Default easing
  • Optional $essential argument (default false) to control whether transition is disabled when reduced motion is preferred

Related:

Testing and review

See "Preview links" above.

Unless system preferences are configured to prefer reduced motion, there should be no changes in the appearance of animated transition effects.

Instructions for configuring reduced motion preference:


Before opening this PR, make sure you’ve done whichever of these applies to you:

  • Confirm that this code follows the 18F Front End Coding Style Guide and Accessibility Guide.
  • Run git pull origin [base branch] to pull in the most recent updates from your base and check for merge conflicts. (Often, the base branch is develop).
  • Run npm run prettier:sass to format any Sass updates.
  • Run npm test and confirm that all tests pass.
  • Run your code through HTML_CodeSniffer and make sure it’s error free.

@aduth aduth requested a review from a team as a code owner December 20, 2024 15:38
@aduth
Copy link
Contributor Author

aduth commented Jan 22, 2025

This addresses all transition styles in stylesheets. I discovered there's also one use of animation which should probably similarly be disabled when reduced motion is preferred.

animation: slidein-left 0.3s ease-in-out;

A couple ideas:

  • We could create a u-animation mixin very similar to what's introduced here with u-transition
  • Alternatively, we could refactor the approach to either inline the media-query, or introduce a mixin which wraps @content with @media not(prefers-reduced-motion)

@mejiaj
Copy link
Contributor

mejiaj commented Feb 3, 2025

I've created a local branch to get the previews and added them to the description.

You might have to refresh the page if component isn't working

CC @uswds/a11y

Copy link
Contributor

@mejiaj mejiaj left a comment

Choose a reason for hiding this comment

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

@aduth thanks for submitting this! I've tested with both Reduce motion settings and everything looks good. Minor suggestion for SASSDoc mixin.

I personally, prefer reducing motion.


I also want to make sure I'm understanding the second point in this comment correctly.

  • Alternatively, we could refactor the approach to either inline the media-query, or introduce a mixin which wraps @content with @media not(prefers-reduced-motion)

Do you mean inline prefers-reduced-motion strictly for this single animation? If so, it seems fair to add it inline because:

  1. We're not using many animations and it seems unnecessary to create a mixin for this
  2. The animation itself is only found in this file
  3. We already have several other media queries in usa-nav, so wouldn't look out of place

@aduth aduth force-pushed the aduth-reduced-motion branch from f374089 to 6ca2a6f Compare February 4, 2025 15:55
@aduth
Copy link
Contributor Author

aduth commented Feb 4, 2025

Do you mean inline prefers-reduced-motion strictly for this single animation? If so, it seems fair to add it inline because:

Yep, that's what I meant. I agree that -- at least in the short term -- adding the media query to the existing style is the most direct option. Maybe an extra mixin could be added in the future.

Updated in 6ca2a6f.

@mejiaj mejiaj self-requested a review February 5, 2025 20:31
@mahoneycm mahoneycm self-requested a review February 6, 2025 16:16
Copy link
Contributor

@mahoneycm mahoneycm left a comment

Choose a reason for hiding this comment

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

This is great! This will benefit users and developers alike. Thanks @aduth

Left a couple comments for additional considerations but nothing blocking

@@ -42,6 +42,7 @@
@forward "text-indent";
@forward "text";
@forward "top";
@forward "transition";
Copy link
Contributor

Choose a reason for hiding this comment

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

thought: We should consider adding guidance to our Utilities pages to document this new utility for users.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to clarify, this would be a separate pull request in the uswds-site repository, correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

@mahoneycm I can see that, but transitions in USWDS are new and aren't used often. There's not even a dedicated page on the website, so this might be a bigger level of effort than we expect.

I would wait until we a strategy for USWDS animations and transitions as a whole.

Copy link
Contributor

Choose a reason for hiding this comment

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

@aduth correct! Just wanted to flag for internal discussion.

@mejiaj right, just noting we have utility pages that capture the rest of the available utilities, so it's worth discussing if we want to create guidance for this utility in the future

/// @include u-transition('top');
/// @include u-transition('opacity', 'ease-in-out');
/// @include u-transition('all', cubic-bezier(0.17, 0.67, 0.83, 0.67), true);
@mixin u-transition($prop, $easing: $project-easing, $essential: false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Praise: $essential is a nice touch! Matches w3c guidance and allows this utility to be very resilient. Thanks!

Copy link
Contributor

@mejiaj mejiaj 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 quick updates!

@mejiaj mejiaj requested review from heymatthenry and thisisdano and removed request for a team February 7, 2025 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

USWDS - Feature: Add support for prefers-reduced-motion to disable transitions
6 participants