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

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/block-library/src/freeform/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,13 @@

div[data-type="core/freeform"] {
&::before {
transition: border-color 0.1s linear, box-shadow 0.1s linear;
@include reduce-motion("transition");
border: $border-width solid $gray-300;

// Windows High Contrast mode will show this outline.
outline: $border-width solid transparent;

@media not (prefers-reduced-motion) {
transition: border-color 0.1s linear, box-shadow 0.1s linear;
}
}

&.is-selected::before {
Expand Down
6 changes: 4 additions & 2 deletions packages/block-library/src/gallery/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,14 @@
top: -2px;
margin: $grid-unit-10;
z-index: z-index(".block-library-gallery-item__inline-menu");
transition: box-shadow 0.2s ease-out;
@include reduce-motion("transition");
border-radius: $radius-small;
background: $white;
border: $border-width solid $gray-900;

@media not (prefers-reduced-motion) {
transition: box-shadow 0.2s ease-out;
}
t-hamano marked this conversation as resolved.
Show resolved Hide resolved

&:hover {
box-shadow: $elevation-x-small;
}
Expand Down
24 changes: 17 additions & 7 deletions packages/block-library/src/image/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
vertical-align: bottom;
box-sizing: border-box;

@media (prefers-reduced-motion: no-preference) {
@media not (prefers-reduced-motion) {
&.hide {
visibility: hidden;
}
Expand Down Expand Up @@ -167,7 +167,9 @@
text-align: center;
padding: 0;
border-radius: 4px;
transition: opacity 0.2s ease;
@media not (prefers-reduced-motion) {
transition: opacity 0.2s ease;
}

&:focus-visible {
outline: 3px auto rgb(90 90 90 / 25%);
Expand Down Expand Up @@ -280,21 +282,29 @@
// or faster than the scrim to give a sense of depth.
&.active {
visibility: visible;
animation: both turn-on-visibility 0.25s;
@media not (prefers-reduced-motion) {
animation: both turn-on-visibility 0.25s;
}
img {
animation: both turn-on-visibility 0.35s;
@media not (prefers-reduced-motion) {
animation: both turn-on-visibility 0.35s;
}
}
}
&.show-closing-animation {
&:not(.active) {
animation: both turn-off-visibility 0.35s;
@media not (prefers-reduced-motion) {
animation: both turn-off-visibility 0.35s;
}
img {
animation: both turn-off-visibility 0.25s;
@media not (prefers-reduced-motion) {
animation: both turn-off-visibility 0.25s;
}
}
}
}

@media (prefers-reduced-motion: no-preference) {
@media not (prefers-reduced-motion) {
&.zoom {
&.active {
opacity: 1;
Expand Down
11 changes: 7 additions & 4 deletions packages/block-library/src/navigation/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ $navigation-icon-size: 24px;

// Hide until hover or focus within.
opacity: 0;
transition: opacity 0.1s linear;
@media not (prefers-reduced-motion) {
transition: opacity 0.1s linear;
}
visibility: hidden;

// Don't take up space when the menu is collapsed.
Expand Down Expand Up @@ -502,9 +504,10 @@ button.wp-block-navigation-item__content {
background-color: inherit;

// Animation.
animation: overlay-menu__fade-in-animation 0.1s ease-out;
animation-fill-mode: forwards;
@include reduce-motion("animation");
@media not (prefers-reduced-motion) {
animation: overlay-menu__fade-in-animation 0.1s ease-out;
animation-fill-mode: forwards;
}

// Try to inherit any root paddings set, so the X can align to a top-right aligned menu.
padding-top: clamp(1rem, var(--wp--style--root--padding-top), 20rem);
Expand Down
9 changes: 6 additions & 3 deletions packages/block-library/src/social-links/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@
.wp-block-social-link {
display: block;
border-radius: 9999px; // This makes it pill-shaped instead of oval, in cases where the image fed is not perfectly sized.
transition: transform 0.1s ease;
@include reduce-motion("transition");
@media not (prefers-reduced-motion) {
transition: transform 0.1s ease;
}

// Dimensions.
height: auto;
Expand All @@ -80,7 +81,9 @@
align-items: center;
display: flex;
line-height: 0;
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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@t-hamano So in that case, what would be better here - applying transition: none or not applying transition at all?

I think removing altogether would be a better option but I want your opinion on this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think removing altogether would be a better option

I think so.

}

&:hover {
Expand Down
Loading