Skip to content

Commit 854f4df

Browse files
authoredOct 30, 2022
fix: modifierKey: null is not respected (#547)
1 parent 15df8ff commit 854f4df

File tree

11 files changed

+8622
-4302
lines changed

11 files changed

+8622
-4302
lines changed
 

‎.changeset/itchy-jobs-cross.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@use-gesture/core': patch
3+
---
4+
5+
feat (pinch):
6+
7+
- `pinchOnwheel: false` prevents pinching with wheel.

‎demo/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@
1717
"leva": "*",
1818
"lodash-move": "^1.1.1",
1919
"lodash.clamp": "^4.0.3",
20-
"react": "^18.1.0",
21-
"react-dom": "^18.1.0",
20+
"react": "^18.2.0",
21+
"react-dom": "^18.2.0",
2222
"react-use-measure": "^2.1.1",
2323
"screenlog": "^0.3.0",
2424
"three": "^0.140.2",
2525
"wouter": "^2.7.4"
2626
},
2727
"devDependencies": {
2828
"@types/lodash.clamp": "^4.0.7",
29-
"@types/react": "^18.0.9",
30-
"@types/react-dom": "^18.0.4",
29+
"@types/react": "^18.0.24",
30+
"@types/react-dom": "^18.0.8",
3131
"@types/three": "^0.140.0",
3232
"@vitejs/plugin-react": "^1.3.2",
33-
"typescript": "^4.8.2",
33+
"typescript": "^4.8.4",
3434
"typescript-plugin-css-modules": "^3.4.0",
3535
"vite": "2.9.9"
3636
}

‎documentation/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717
"@use-gesture/react": "*",
1818
"@use-gesture/vanilla": "*",
1919
"animejs": "^3.2.1",
20-
"classnames": "^2.2.6",
20+
"classnames": "^2.3.2",
2121
"gatsby": "^4.12.1",
22-
"gatsby-plugin-google-analytics": "^4.12.1",
22+
"gatsby-plugin-google-analytics": "^4.24.0",
2323
"gatsby-plugin-pnpm": "^1.2.10",
2424
"lethargy": "^1.0.9",
2525
"leva": "^0.9.25",
2626
"mdx-observable": "^0.2.0",
2727
"parse-numeric-range": "^1.3.0",
28-
"react": "^18.1.0",
29-
"react-dom": "^18.1.0",
28+
"react": "^18.2.0",
29+
"react-dom": "^18.2.0",
3030
"react-player": "^2.10.0",
3131
"react-toastify": "^8.1.0",
3232
"smooth-doc": "^8.0.1",

‎documentation/pages/docs/options.mdx

+4-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ Here are all options that can be applied to gestures.
109109
| [`bounds`](#bounds) | **xy** | Limits the gesture `offset` to the specified bounds. |
110110
| [`scaleBounds`](#scalebounds) | **pinch** | Limits the scale `offset` to the specified bounds. |
111111
| [`angleBounds`](#anglebounds) | **pinch** | Limits the angle `offset` to the specified bounds. |
112-
| [`modifierKey`](#modifierKey) | **pinch** | The modifier key that triggers a scale when wheeling. Defaults to `'ctrlKey'`. Can be null. |
112+
| [`modifierKey`](#modifierKey) | **pinch** | The modifier key that triggers a scale when wheeling. Defaults to `'ctrlKey'`. Can be `null`. |
113+
| `pinchOnWheel` | **pinch** | If `false`, pinching with the wheel will be disabled. |
113114
| [`rubberband`](#rubberband) | **all** | The elasticity coefficient of the gesture when going out of bounds. When set to `true`, the elasticity coefficient will be defaulted to `0.15` |
114115
| [`transform`](#transform) | **all** | A function that you can use to transform pointer values. Useful to map your screen coordinates to custom space coordinates such as a canvas. |
115116
| [`filterTaps`](#filtertaps) | **drag** | If `true`, the component won't trigger your drag logic if the user just clicked on the component. |
@@ -340,6 +341,8 @@ If you set `keys` to `false`, your drag handler won't respond to keyboard events
340341

341342
This option lets you set the modifier key that triggers a scale gesture when using wheel inside the `onPinch` handler.
342343

344+
When `null`, pinching will be triggered using wheel _without_ the need of pressing a modifier key.
345+
343346
### pointer.buttons
344347

345348
<Specs gestures={['drag']} types={['number', 'number[]']} defaultValue="1" />

‎package.json

+24-24
Original file line numberDiff line numberDiff line change
@@ -72,39 +72,39 @@
7272
]
7373
},
7474
"devDependencies": {
75-
"@babel/core": "^7.17.10",
76-
"@babel/plugin-syntax-flow": "^7.16.7",
77-
"@babel/plugin-transform-react-jsx": "^7.17.3",
78-
"@babel/preset-env": "^7.17.10",
79-
"@babel/preset-react": "^7.16.7",
80-
"@babel/preset-typescript": "^7.16.7",
81-
"@changesets/cli": "^2.22.0",
82-
"@preconstruct/cli": "^2.1.5",
75+
"@babel/core": "^7.19.6",
76+
"@babel/plugin-syntax-flow": "^7.18.6",
77+
"@babel/plugin-transform-react-jsx": "^7.19.0",
78+
"@babel/preset-env": "^7.19.4",
79+
"@babel/preset-react": "^7.18.6",
80+
"@babel/preset-typescript": "^7.18.6",
81+
"@changesets/cli": "^2.25.1",
82+
"@preconstruct/cli": "^2.2.2",
8383
"@size-limit/preset-small-lib": "^7.0.8",
84-
"@testing-library/jest-dom": "^5.16.4",
84+
"@testing-library/jest-dom": "^5.16.5",
8585
"@testing-library/react": "^13.2.0",
8686
"@types/jest": "^27.5.1",
87-
"@types/node": "^17.0.33",
88-
"@types/react": "^18.0.9",
89-
"@types/react-dom": "^18.0.4",
90-
"@typescript-eslint/eslint-plugin": "^5.23.0",
91-
"@typescript-eslint/parser": "^5.23.0",
87+
"@types/node": "^18.11.7",
88+
"@types/react": "^18.0.24",
89+
"@types/react-dom": "^18.0.8",
90+
"@typescript-eslint/eslint-plugin": "^5.41.0",
91+
"@typescript-eslint/parser": "^5.41.0",
9292
"babel-jest": "^27.5.1",
93-
"eslint": "^8.15.0",
93+
"eslint": "^8.26.0",
9494
"eslint-config-react-app": "^7.0.1",
95-
"eslint-plugin-jest-dom": "^4.0.1",
96-
"eslint-plugin-react-hooks": "^4.5.0",
97-
"eslint-plugin-testing-library": "^5.5.0",
95+
"eslint-plugin-jest-dom": "^4.0.2",
96+
"eslint-plugin-react-hooks": "^4.6.0",
97+
"eslint-plugin-testing-library": "^5.9.1",
9898
"husky": "^8.0.1",
9999
"jest": "^27.5.1",
100-
"pnpm": "^7.1.0",
100+
"pnpm": "^7.14.1",
101101
"postinstall-postinstall": "^2.1.0",
102-
"prettier": "^2.6.2",
102+
"prettier": "^2.7.1",
103103
"pretty-quick": "^3.1.3",
104-
"react": "^18.1.0",
105-
"react-dom": "^18.1.0",
104+
"react": "^18.2.0",
105+
"react-dom": "^18.2.0",
106106
"size-limit": "^7.0.8",
107-
"tsd": "^0.20.0",
108-
"typescript": "^4.8.2"
107+
"tsd": "^0.24.1",
108+
"typescript": "^4.8.4"
109109
}
110110
}

‎packages/core/src/config/pinchConfigResolver.ts

+3
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,8 @@ export const pinchConfigResolver = {
4747
modifierKey(value: ModifierKey) {
4848
if (value === undefined) return 'ctrlKey'
4949
return value
50+
},
51+
pinchOnWheel(value = true) {
52+
return value
5053
}
5154
}

‎packages/core/src/engines/PinchEngine.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ export class PinchEngine extends Engine<'pinch'> {
292292
}
293293
// we try to set a passive listener, knowing that in any case React will
294294
// ignore it.
295-
bindFunction('wheel', '', this.wheel.bind(this), { passive: false })
295+
if (this.config.pinchOnWheel) {
296+
bindFunction('wheel', '', this.wheel.bind(this), { passive: false })
297+
}
296298
}
297299
}

‎packages/core/src/types/config.ts

+4
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ export type PinchConfig = GestureOptions<'pinch'> & {
121121
* Key that triggers scale when using the wheel. Defaults to `'ctrlKey'`.
122122
*/
123123
modifierKey?: ModifierKey
124+
/**
125+
* Whether wheel should trigger a pinch at all.
126+
*/
127+
pinchOnWheel?: boolean
124128
}
125129

126130
export type DragBounds = Bounds | HTMLElement | { current: HTMLElement | null }

‎packages/core/src/types/internalConfig.ts

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export type InternalPinchOptions = InternalGestureOptions<'pinch'> & {
5555
device: 'gesture' | 'pointer' | 'touch' | undefined
5656
lockDirection: boolean
5757
modifierKey: ModifierKey
58+
pinchOnWheel: boolean
5859
}
5960

6061
type MoveAndHoverMouseOnly = {

0 commit comments

Comments
 (0)
Please sign in to comment.