Closed
Description
What problem does this address?
If we use transition or animation CSS, we are expected to use the reduce-motion
mixin. Example:
.selector {
transition: all 400ms linear;
@include reduce-motion("transition");
}
This code compiles to the following to respect the user's preference and disable animations:
.selector {
transition: all 400ms linear;
}
@media (prefers-reduced-motion:reduce){
.selector {
transition-delay:0s;
transition-duration:0s;
}
}
However, there are many places where transition
or animation
is used without this mixin.
What is your proposed solution?
We could update stylelint to enforce this rule, but since this is a custom rule, we would need to add our own plugin. I'm not sure if it would be worth creating a custom plugin to enforce this rule. For now, I think it's best to find the missing mixin and add it.
Steps to get started
- Search for
transition:
oranimation:
in the.scss
files in the Gutenberg project. - Make sure the value is something other than
none
. - Check to see if the
reduce-motion
mixin exists. If it doesn't exist, we may need one. - Identify the component that has that CSS applied.
- In your Chrome browser, change the "Emulate CSS media feature prefers-reduced-motion" setting to
reduce
.
https://developer.chrome.com/docs/devtools/rendering/emulate-css#emulate_css_media_feature_prefers-reduced-motion - Do something to that component that will cause a transition or animation (such as hover or focus).
- If transition or animation occurs, it means the user's animation preference is not being respected, so add the mixin.
Update: We aim to use standard patterns across projects rather than using mixins.
@media not ( prefers-reduced-motion ) {
transition: all 400ms linear;
}
Activity
himanshupathak95 commentedon Dec 25, 2024
Hey @t-hamano, Thanks for raising this.
I will raise a PR to fix this.
t-hamano commentedon Dec 25, 2024
@himanshupathak95 Thanks for addressing this issue.
If you don't mind, could you provide some screenshots of which components each of the reduce-motion mixins affects so we can make sure they work as expected?
Also, you don't need to tackle them all at once. If there are too many to tackle, you can tackle them package by package.
himanshupathak95 commentedon Dec 25, 2024
@t-hamano, I am thinking of doing this package by package since there are a lot of places that need to change and there must be distinction amongst them to test and discuss each package correctly in isolation.
I am thinking maybe we can create separate PRs to track packages specifically and execute the changes so we don't break anything. Please let me know what you think.
t-hamano commentedon Dec 25, 2024
Yes, I think it's a good idea to submit a PR for each package 👍
mirka commentedon Dec 25, 2024
No strong opinion, but I wanted to note that in
@wordpress/components
we decided to adopt this standard pattern instead of a mixin:It isn't any less ergonomic, it's immediately understandable without knowledge of a custom mixin implementation, and we end up with fewer lines of CSS. Would it be worth considering this pattern for the wider codebase as well?
t-hamano commentedon Dec 26, 2024
@mirka Thanks for the feedback!
That's a good idea. I think it might be better to proceed in the following order:
reduce-motion
mixin itself is missing, wrap the transition or animation in the media query.reduce-motion
mixin is already used with the media query.34 remaining items