-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Modify reduce-motion mixin so that it works for transitions too. #15850
Conversation
assets/stylesheets/_mixins.scss
Outdated
@@ -340,6 +341,7 @@ | |||
@mixin reduce-motion { | |||
@media (prefers-reduced-motion: reduce) { | |||
animation-duration: 1ms !important; | |||
transition-duration: 0s !important; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this 01 when the animation duration is 1ms? Should they both be 1ms?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the original PR, I noticed some Safari issues when animation-duration
was set to 0s
: I couldn't get it to reliably render the end-state, which was preventing menus and panels from opening. 😕
I haven't noticed the same issues with transition
for some reason, so I think it's fine to use 0s
there.
This is very clever, and very welcome. It seems to work for me, so 👍 👍 for this. I left a small question, so I could use a sanity check on that one. But otherwise, nice work! |
Oh yeah, I meant to get back to this. Glad you remembered 😄
This makes sense but including both in a single mixin keeps things simple.
This is a cool and efficient idea!
This is kinda what I was thinking.
More and more, I think we'll start seeing that as a staple for most websites. Similar to how we see the "global" I agree that it feels careless to use a global like that but I honestly can't think of one situation where it would cause a problem. It might actually be less problematic since it blankets everything rather than needing to be meticulously added to individual rules. |
pointer-events: none; | ||
transition: border-color 0.1s linear, box-shadow 0.1s linear; | ||
@include reduce-motion; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So how does SASS compile this? Is the @media query
always before or after the original rule?
Maybe it's not consistent enough to count on but I'm wondering if !important
is even necessary if the @media
comes after...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well theoretically the compiled order shouldn't matter, right? Since the added media query adds another level of specificity that would usually override the existing rule.
With that in mind, I the !important
only becomes necessary if someone happened to add a competing transition-duration
property for the same element, later on in the stylesheet and more specific than this one. Probably rare?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well theoretically the compiled order shouldn't matter, right? Since the added media query adds another level of specificity that would usually override the existing rule.
That's what I thought too until a couple days ago. According to the spec, media queries don't add any weight.
Maybe some browsers don't follow that cause I could swear I've seen otherwise. 😕
I don't think !important
is that out of line here. Might as well leave it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried removing it in 5350c8e, and haven't found any instances where these rules are ignored yet. 🤷♂️
Seeing as that's the case, I think we might as well keep it out until we determine we definitely need it.
Totally agree. I'm mostly scared of the possibility that this breaks something important, and it isn't reported and fixed quickly because people aren't frequently testing with this setting turned on. 😞 For instance, the I guess for now, I'll look into breaking these out into two separate |
Good point. Change one of the examples at the top of this page to So yeah, individual mixins would probably be best. |
The idea of two separate mixins seemed a little confusing to me, so I tried out a slightly different idea. Let me know if this is too obscure of a method: We'd keep one mixin, that'd accept two different values, depending on the type of motion property:
If someone were to leave the property variable empty, we'd fall back to including both. This seems pretty flexible to me, and keeps these overrides together in one place. Here's how it's done: gutenberg/assets/stylesheets/_mixins.scss Lines 341 to 362 in 5350c8e
We use somewhat similar mixins for z-index and long-content fades. Let me know your thoughts! |
That's perfect! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, for this.
Code looks good, and feedback from Marty seems to be mostly addressed. What unknowns that may still be present can surely be addressed in subsequent PRs if need be.
The documentation is also already in place: https://developer.wordpress.org/block-editor/designers/animation/#accessibility-considerations
Nothing comes to mind as to what we can do, more than this, to advise third parties for how to best design with this in mind.
I also took a quick spin to verify the behavior:
Thanks folks! Happy to get this merged in. Also, an extra kudos to @ryelle for bringing this up originally over in #8029 (comment). 🎉 |
This PR expands the
reduce-motion
mixin created in #14021 to account fortransition
-based motion as well. props to @m-e-h for the suggestion.This PR is a blunt instrument in its current state — I've added a
transition-duration: 0s !important
rule to the mixin and applied it to every single place we're usingtransition
. It seems to work just fine like that, but I'm not sure that's actually the best way to handle this. Some other options:transition
andanimation
properties. This would theoretically allow us to stop using!important
, too. (Example)!important
all over the place anyway, maybe we should switch to using a single global declaration for this media query, rather than placing this in a bunch of different places at once. The downside of this is the chance that the rules cause issues in some places, and go undetected because people aren't testing this option.Any thoughts are greatly appreciated!