Skip to content

Commit 2777107

Browse files
EEwingElliott Ewing
andauthored
feat: Add Left, Right, and Middle click pan options (#420)
Co-authored-by: Elliott Ewing <quent@rivalesports.com>
1 parent 1e38727 commit 2777107

4 files changed

Lines changed: 28 additions & 0 deletions

File tree

src/constants/state.constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export const initialSetup: LibrarySetup = {
3434
velocityDisabled: false,
3535
lockAxisX: false,
3636
lockAxisY: false,
37+
allowLeftClickPan: true,
38+
allowMiddleClickPan: true,
39+
allowRightClickPan: true,
3740
activationKeys: [],
3841
excluded: [],
3942
},

src/core/instance.core.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ export class ZoomPanPinch {
208208
const keysPressed = this.isPressingKeys(this.setup.panning.activationKeys);
209209
if (!keysPressed) return;
210210

211+
if(event.button == 0 && !this.setup.panning.allowLeftClickPan) return;
212+
if(event.button == 1 && !this.setup.panning.allowMiddleClickPan) return;
213+
if(event.button == 2 && !this.setup.panning.allowRightClickPan) return;
214+
211215
event.preventDefault();
212216
event.stopPropagation();
213217

src/models/context.model.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ export type ReactZoomPanPinchProps = {
8181
velocityDisabled?: boolean;
8282
lockAxisX?: boolean;
8383
lockAxisY?: boolean;
84+
allowLeftClickPan?: boolean;
85+
allowMiddleClickPan?: boolean;
86+
allowRightClickPan?: boolean;
8487
activationKeys?: string[];
8588
excluded?: string[];
8689
};

src/stories/docs/props.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,24 @@ export const wrapperPropsTable: ComponentProps = {
248248
description:
249249
"Disable the panning feature for the Y axis (prevents vertical panning).",
250250
},
251+
allowLeftClickPan: {
252+
type: ["boolean"],
253+
defaultValue: String(initialSetup.panning.allowLeftClickPan),
254+
description:
255+
"Allow left click to initiate panning",
256+
},
257+
allowMiddleClickPan: {
258+
type: ["boolean"],
259+
defaultValue: String(initialSetup.panning.allowMiddleClickPan),
260+
description:
261+
"Allow middle click to initiate panning",
262+
},
263+
allowRightClickPan: {
264+
type: ["boolean"],
265+
defaultValue: String(initialSetup.panning.allowRightClickPan),
266+
description:
267+
"Allow right click to initiate panning",
268+
},
251269
activationKeys: {
252270
type: ["string[]"],
253271
defaultValue: String(initialSetup.panning.activationKeys),

0 commit comments

Comments
 (0)