Skip to content

Commit 0ddee01

Browse files
committed
feat: disabled wave effect if prefers-reduced-motion: set to reduce
Resolves #740
1 parent d42141f commit 0ddee01

File tree

4 files changed

+34
-14
lines changed

4 files changed

+34
-14
lines changed

README.md

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ After installing and registering the plugin, this is all you need to get started
7474
- [trigger](#trigger)
7575
- [disabled](#disabled)
7676
- [respectDisabledAttribute](#respectdisabledattribute)
77+
- [respectPrefersReducedMotion](#respectprefersreducedmotion)
7778
- [stopPropagation](#stoppropagation)
7879
- [tagName](#tagname)
7980
- [Using triggers](#using-triggers)
@@ -240,20 +241,21 @@ export default {
240241

241242
### Summary
242243

243-
| Name | Default | Type |
244-
| ----------------------------------------------------- | :--------------: | ----------------------------- |
245-
| [color](#color) | `"currentColor"` | `string` |
246-
| [initialOpacity](#initialopacity) | `0.2` | `number` |
247-
| [finalOpacity](#finalopacity) | `0.1` | `number` |
248-
| [duration](#duration) | `0.4` | `number` |
249-
| [dissolveDuration](#dissolveduration) | `0.15` | `number` |
250-
| [easing](#easing) | `ease-out` | `string` |
251-
| [cancellationPeriod](#cancellationperiod) | `75` | `number` |
252-
| [trigger](#trigger) | `"auto"` | `string \| boolean \| "auto"` |
253-
| [disabled](#disabled) | `false` | `boolean` |
254-
| [respectDisabledAttribute](#respectdisabledattribute) | `true` | `boolean` |
255-
| [stopPropagation](#stoppropagation) | `false` | `boolean` |
256-
| [tagName](#tagname) | `"div"` | `string` |
244+
| Name | Default | Type |
245+
| ------------------------------------------------------ | :--------------: | ----------------------------- |
246+
| [color](#color) | `"currentColor"` | `string` |
247+
| [initialOpacity](#initialopacity) | `0.2` | `number` |
248+
| [finalOpacity](#finalopacity) | `0.1` | `number` |
249+
| [duration](#duration) | `0.4` | `number` |
250+
| [dissolveDuration](#dissolveduration) | `0.15` | `number` |
251+
| [easing](#easing) | `ease-out` | `string` |
252+
| [cancellationPeriod](#cancellationperiod) | `75` | `number` |
253+
| [trigger](#trigger) | `"auto"` | `string \| boolean \| "auto"` |
254+
| [disabled](#disabled) | `false` | `boolean` |
255+
| [respectDisabledAttribute](#respectdisabledattribute) | `true` | `boolean` |
256+
| [respectPrefersReducedMotion](#respectpreferredmotion) | `true` | `boolean` |
257+
| [stopPropagation](#stoppropagation) | `false` | `boolean` |
258+
| [tagName](#tagname) | `"div"` | `string` |
257259

258260
### Details
259261

@@ -545,6 +547,13 @@ export default {
545547
<button v-wave="{respectDisabledAttribute: false}" disabled>Click me!</button>
546548
```
547549

550+
#### respectPrefersReducedMotion
551+
552+
- **type:** `boolean`
553+
- _default:_ `true`
554+
555+
> If `true`, the wave effect will be disabled if the user's [`prefers-reduced-motion`](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion) preference is set to `reduce`.
556+
548557
#### stopPropagation
549558

550559
- **type:** `boolean`

src/__snapshots__/options.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ exports[`has documented default options 1`] = `
1212
"finalOpacity": 0.1,
1313
"initialOpacity": 0.2,
1414
"respectDisabledAttribute": true,
15+
"respectPrefersReducedMotion": true,
1516
"stopPropagation": false,
1617
"tagName": "div",
1718
"trigger": "auto",

src/options.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ interface IVWaveDirectiveOptions {
102102
*/
103103
respectDisabledAttribute: boolean
104104

105+
/**
106+
* If `true`, the wave effect will be disabled if the user's `prefers-reduced-motion` preference is set to `reduce`.
107+
*
108+
* @default
109+
* true
110+
*/
111+
respectPrefersReducedMotion: boolean
112+
105113
/**
106114
* Prevents the pointerdown event from propagating to parent elements
107115
*
@@ -144,6 +152,7 @@ const DEFAULT_PLUGIN_OPTIONS: IVWavePluginOptions = {
144152
tagName: 'div',
145153
disabled: false,
146154
respectDisabledAttribute: true,
155+
respectPrefersReducedMotion: true,
147156
stopPropagation: false,
148157
}
149158

src/wave.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const SCALE_FACTOR = 2.05
1616
const wave = (screenPos: Vector, el: HTMLElement, options: IVWaveDirectiveOptions) => {
1717
if (options.disabled) return
1818
if (options.respectDisabledAttribute && el.hasAttribute('disabled')) return
19+
if (options.respectPrefersReducedMotion && window.matchMedia('(prefers-reduced-motion: reduce)').matches) return
1920

2021
const rect = el.getBoundingClientRect()
2122
const computedStyles = window.getComputedStyle(el)

0 commit comments

Comments
 (0)