Skip to content

Commit 5dfaf14

Browse files
feat(a11y): apply prefers-reduced-motion handling for transitions (ant-design#56902)
* up * up * update * update --------- Co-authored-by: 遇见同学 <1875694521@qq.com>
1 parent 5ad1ecd commit 5dfaf14

6 files changed

Lines changed: 26 additions & 4 deletions

File tree

components/button/style/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { CSSInterpolation, CSSObject } from '@ant-design/cssinjs';
22
import { unit } from '@ant-design/cssinjs';
33

44
import { genFocusStyle, resetIcon } from '../../style';
5+
import { genNoMotionStyle } from '../../style/motion';
56
import type { GenerateStyle } from '../../theme/internal';
67
import { genStyleHooks, mergeToken } from '../../theme/internal';
78
import genGroupStyle from './group';
@@ -40,7 +41,7 @@ const genSharedButtonStyle: GenerateStyle<ButtonToken, CSSObject> = (token): CSS
4041
transition: `all ${token.motionDurationMid} ${token.motionEaseInOut}`,
4142
userSelect: 'none',
4243
touchAction: 'manipulation',
43-
44+
...genNoMotionStyle(),
4445
'&:disabled > *': {
4546
pointerEvents: 'none',
4647
},
@@ -80,7 +81,7 @@ const genSharedButtonStyle: GenerateStyle<ButtonToken, CSSObject> = (token): CSS
8081

8182
[`${componentCls}-loading-icon`]: {
8283
transition: ['width', 'opacity', 'margin']
83-
.map((transition) => `${transition} ${motionDurationSlow} ${motionEaseInOut}`)
84+
.map((prop) => `${prop} ${motionDurationSlow} ${motionEaseInOut}`)
8485
.join(','),
8586
},
8687

components/checkbox/style/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { unit } from '@ant-design/cssinjs';
22

33
import { genFocusOutline, resetComponent } from '../../style';
4+
import { genNoMotionStyle } from '../../style/motion';
45
import type { FullToken, GenerateStyle } from '../../theme/internal';
56
import { genStyleHooks, mergeToken } from '../../theme/internal';
67

@@ -99,6 +100,7 @@ export const genCheckboxStyle: GenerateStyle<CheckboxToken> = (token) => {
99100
borderRadius: token.borderRadiusSM,
100101
borderCollapse: 'separate',
101102
transition: `all ${token.motionDurationSlow}`,
103+
...genNoMotionStyle(),
102104

103105
// Checkmark
104106
'&:after': {
@@ -116,6 +118,7 @@ export const genCheckboxStyle: GenerateStyle<CheckboxToken> = (token) => {
116118
opacity: 0,
117119
content: '""',
118120
transition: `all ${token.motionDurationFast} ${token.motionEaseInBack}, opacity ${token.motionDurationFast}`,
121+
...genNoMotionStyle(),
119122
},
120123

121124
// Wrapper > Checkbox > input
@@ -173,6 +176,7 @@ export const genCheckboxStyle: GenerateStyle<CheckboxToken> = (token) => {
173176
opacity: 1,
174177
transform: 'rotate(45deg) scale(1) translate(-50%,-50%)',
175178
transition: `all ${token.motionDurationMid} ${token.motionEaseOutBack} ${token.motionDurationFast}`,
179+
...genNoMotionStyle(),
176180
},
177181

178182
// Hover on checked checkbox directly

components/style/motion/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
slideUpIn,
2323
slideUpOut,
2424
} from './slide';
25+
import { genNoMotionStyle } from './util';
2526
import {
2627
initZoomMotion,
2728
zoomBigIn,
@@ -42,6 +43,7 @@ export {
4243
fadeIn,
4344
fadeOut,
4445
genCollapseMotion,
46+
genNoMotionStyle,
4547
initFadeMotion,
4648
initMoveMotion,
4749
initSlideMotion,

components/style/motion/util.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { CSSObject } from '@ant-design/cssinjs';
2+
3+
export const genNoMotionStyle = (): CSSObject => {
4+
return {
5+
'@media (prefers-reduced-motion: reduce)': {
6+
transition: 'none',
7+
animation: 'none',
8+
},
9+
};
10+
};

components/style/motion/zoom.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ type ZoomMotionTypes =
162162
| 'zoom-right'
163163
| 'zoom-up'
164164
| 'zoom-down';
165+
165166
const zoomMotion: Record<ZoomMotionTypes, { inKeyframes: Keyframes; outKeyframes: Keyframes }> = {
166167
zoom: {
167168
inKeyframes: zoomIn,

components/switch/style/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { unit } from '@ant-design/cssinjs';
33
import { FastColor } from '@ant-design/fast-color';
44

55
import { genFocusStyle, resetComponent } from '../../style';
6+
import { genNoMotionStyle } from '../../style/motion';
67
import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';
78
import { genStyleHooks, mergeToken } from '../../theme/internal';
89

@@ -208,6 +209,7 @@ const genSwitchHandleStyle: GenerateStyle<SwitchToken, CSSObject> = (token) => {
208209
width: handleSize,
209210
height: handleSize,
210211
transition: `all ${token.switchDuration} ease-in-out`,
212+
...genNoMotionStyle(),
211213

212214
'&::before': {
213215
position: 'absolute',
@@ -220,6 +222,7 @@ const genSwitchHandleStyle: GenerateStyle<SwitchToken, CSSObject> = (token) => {
220222
boxShadow: handleShadow,
221223
transition: `all ${token.switchDuration} ease-in-out`,
222224
content: '""',
225+
...genNoMotionStyle(),
223226
},
224227
},
225228

@@ -270,7 +273,7 @@ const genSwitchInnerStyle: GenerateStyle<SwitchToken, CSSObject> = (token) => {
270273
transition: [`padding-inline-start`, `padding-inline-end`]
271274
.map((prop) => `${prop} ${switchDuration} ease-in-out`)
272275
.join(', '),
273-
276+
...genNoMotionStyle(),
274277
[`${switchInnerCls}-checked, ${switchInnerCls}-unchecked`]: {
275278
display: 'block',
276279
color: token.colorTextLightSolid,
@@ -280,6 +283,7 @@ const genSwitchInnerStyle: GenerateStyle<SwitchToken, CSSObject> = (token) => {
280283
transition: [`margin-inline-start`, `margin-inline-end`]
281284
.map((prop) => `${prop} ${switchDuration} ease-in-out`)
282285
.join(', '),
286+
...genNoMotionStyle(),
283287
},
284288

285289
[`${switchInnerCls}-checked`]: {
@@ -347,7 +351,7 @@ const genSwitchStyle = (token: SwitchToken): CSSObject => {
347351
cursor: 'pointer',
348352
transition: `all ${token.motionDurationMid}`,
349353
userSelect: 'none',
350-
354+
...genNoMotionStyle(),
351355
[`&:hover:not(${componentCls}-disabled)`]: {
352356
background: token.colorTextTertiary,
353357
},

0 commit comments

Comments
 (0)