Skip to content

Commit

Permalink
chore: update pan-event
Browse files Browse the repository at this point in the history
  • Loading branch information
segunadebayo committed Oct 8, 2021
1 parent 6cd58ea commit 5b4d8ef
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/selfish-spiders-push.md
@@ -0,0 +1,5 @@
---
"@chakra-ui/utils": patch
---

Fix issue where pan-event utils don't work within iframe
5 changes: 5 additions & 0 deletions .changeset/sour-pigs-impress.md
@@ -0,0 +1,5 @@
---
"@chakra-ui/slider": patch
---

Fix issue where value can't be changed when range-slider thumbs are stacked
24 changes: 17 additions & 7 deletions packages/utils/src/pan-event.ts
Expand Up @@ -6,16 +6,17 @@
*/

import sync, { cancelSync, getFrameData } from "framesync"
import { getEventWindow } from "./dom"
import { distance, noop, pipe } from "./function"
import {
isMouseEvent,
extractEventInfo,
addPointerEvent,
AnyPointerEvent,
extractEventInfo,
isMouseEvent,
isMultiTouchEvent,
Point,
PointerEventInfo,
isMultiTouchEvent,
} from "./pointer-event"
import { pipe, distance, noop } from "./function"

/**
* The event information passed to pan event handlers like `onPan`, `onPanStart`.
Expand Down Expand Up @@ -84,6 +85,11 @@ export interface PanSessionHandlers {

type PanSessionHistory = TimestampedPoint[]

export type PanSessionOptions = {
threshold?: number
window?: Window
}

/**
* @internal
*
Expand Down Expand Up @@ -116,11 +122,15 @@ export class PanSession {
*/
private threshold = 3

private win: typeof globalThis

constructor(
event: AnyPointerEvent,
handlers: Partial<PanSessionHandlers>,
threshold?: number,
) {
this.win = getEventWindow(event)

// If we have more than one touch, don't start detecting this gesture
if (isMultiTouchEvent(event)) return

Expand All @@ -146,9 +156,9 @@ export class PanSession {

// attach event listeners and return a single function to remove them all
this.removeListeners = pipe(
addPointerEvent(window, "pointermove", this.onPointerMove),
addPointerEvent(window, "pointerup", this.onPointerUp),
addPointerEvent(window, "pointercancel", this.onPointerUp),
addPointerEvent(this.win, "pointermove", this.onPointerMove),
addPointerEvent(this.win, "pointerup", this.onPointerUp),
addPointerEvent(this.win, "pointercancel", this.onPointerUp),
)
}

Expand Down

0 comments on commit 5b4d8ef

Please sign in to comment.