<portal> blog post: include 'prefers-reduced-motion' in examples
In https://web.dev/hands-on-portals/, please consider including prefers-reduced-motion, in respect of motion-triggered vestibular spectrum disorder. This helps create awareness of the prefers-reduced-motion media query, but also if devs resort to copy/pasting from the examples we'll just have a11y baked in for those sites.
oh good point. I'm just about to head out on vacation but I can look into this when I come back.
@uskay is this something you might be able to add?
Yes I should be able to do that. Thank you for the heads up. I'll work on it as soon as I get a chance.
rad thank you!
Hey @uskay I wanted to check if you still think you'll have time to do this? If not I can see if someone else on our team is free to add it.
Apologies. I looked into this and there are multiple way to implement this. The easiest way is using the prefers-reduced-motion media query in the CSS and setting the transition duration to 0.001s (which should be an instant transition for human eyes). The reason for not setting the transition-property value to none is that it'll be a lot more simpler to commonly use the transitionend event as the activate trigger.
.portal-transition {
transition:
transform 0.4s,
bottom 0.7s,
left 0.7s,
opacity 1.0s;
}
@media (prefers-reduced-motion: reduce) {
.portal-transition {
transition: all 0.001s;
}
}
If we strictly wanted to reduce the motion to none, I can think of a combination of both fixing the style and JavaScript logic. Having the JavaScript implementation is not enough since we need to control the opacity transition i.e. fade-in animation as well.
.portal-transition {
transition:
transform 0.4s,
bottom 0.7s,
left 0.7s,
opacity 1.0s;
}
@media (prefers-reduced-motion: reduce) {
.portal-transition {
transition-property: none;
}
}
and
portal.addEventListener('click', evt => {
// Check if the user perferes reduced motion
const mediaQuery = window.matchMedia('(prefers-reduced-motion: reduce)');
if (mediaQuery.matches) {
// Activate without transition
portal.activate();
} else {
// Animate the portal once user interacts
portal.classList.add('portal-reveal');
}
}
As I'm not an expert in accessibility your advice is very much appreciated. I have a feeling I do want to stick with the first option to make the code cleaner IMO (as this should be a short snippet to understand the APIs of Portals).
+1 for option one.