Skip to content

Commit ad396d7

Browse files
committed
feat: add allowPinchZoom
1 parent 6fd19aa commit ad396d7

File tree

7 files changed

+35
-17
lines changed

7 files changed

+35
-17
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import {FocusOn} from 'react-focus-on';
5959
- `[gapMode]` - the way removed ScrollBar would be _compensated_ - margin(default), or padding. See [scroll-locky documentation](https://github.com/theKashey/react-scroll-locky#gap-modes) to find the one you need.
6060
- `[noIsolation]` - disables aria-hidden isolation
6161
- `[inert]` - enables pointer-events isolation (☠️ dangerous, use to disable "parent scrollbars", refer to [react-remove-scroll](https://github.com/theKashey/react-remove-scroll) documentation)
62+
- `[allowPinchZoom]` - enables "pinch-n-zoom" behavior. By default it might be prevented, refer to [react-remove-scroll](https://github.com/theKashey/react-remove-scroll) documentation
6263
---
6364
- `[onActivation]` - on activation callback
6465
- `[onDeactivation]` - on deactivation callback

example/app.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ export default class App extends Component <{}, AppState> {
5858
onActivation={() => console.log("activated")}
5959
onDeactivation={() => console.log("deactivated")}
6060

61+
allowPinchZoom={true}
62+
6163
className="test-class-name"
6264
>
6365
Holala!! {on ? "on" : "off"}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
},
4242
"dependencies": {
4343
"aria-hidden": "^1.1.1",
44-
"react-focus-lock": "^2.2.0",
45-
"react-remove-scroll": "^2.1.1",
44+
"react-focus-lock": "^2.2.1",
45+
"react-remove-scroll": "^2.2.0",
4646
"react-style-singleton": "^2.0.0",
4747
"use-callback-ref": "^1.2.1",
4848
"use-sidecar": "^1.0.1"

src/Effect.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export function Effect({
2626
);
2727

2828
const lastEventTarget = useRef<EventTarget>(null);
29+
const mouseTouches = useRef<number>(0);
2930

3031
React.useEffect(
3132
() => {
@@ -67,15 +68,26 @@ export function Effect({
6768
}
6869
};
6970

71+
const onTouchStart = (event: TouchEvent) => {
72+
onMouseDown(event);
73+
mouseTouches.current = event.touches.length;
74+
};
75+
76+
const onTouchEnd = (event: TouchEvent) => {
77+
mouseTouches.current = event.touches.length;
78+
};
79+
7080
if (activeNode) {
7181
document.addEventListener('keydown', onKeyDown);
7282
document.addEventListener('mousedown', onMouseDown);
73-
document.addEventListener('touchstart', onMouseDown);
83+
document.addEventListener('touchstart', onTouchStart);
84+
document.addEventListener('touchend', onTouchEnd);
7485

7586
return () => {
7687
document.removeEventListener('keydown', onKeyDown);
7788
document.removeEventListener('mousedown', onMouseDown);
78-
document.removeEventListener('touchstart', onMouseDown);
89+
document.removeEventListener('touchstart', onTouchStart);
90+
document.removeEventListener('touchend', onTouchEnd);
7991
};
8092
}
8193
},

src/UI.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const FocusOn = React.forwardRef<HTMLElement, ReactFocusOnSideProps>(
2020
focusLock = true,
2121
returnFocus = true,
2222
inert,
23+
allowPinchZoom,
2324
sideCar,
2425
className,
2526
...rest
@@ -46,6 +47,7 @@ export const FocusOn = React.forwardRef<HTMLElement, ReactFocusOnSideProps>(
4647
...restProps,
4748
sideCar,
4849
shards,
50+
allowPinchZoom,
4951
inert,
5052
enabled: enabled && scrollLock
5153
}}

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface CommonProps {
1919

2020
noIsolation?: boolean;
2121
inert?: boolean;
22+
allowPinchZoom?: boolean;
2223

2324
shards?: Array<React.RefObject<any> | HTMLElement>;
2425
}

yarn.lock

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4515,10 +4515,10 @@ flush-write-stream@^1.0.0:
45154515
inherits "^2.0.1"
45164516
readable-stream "^2.0.4"
45174517

4518-
focus-lock@^0.6.5:
4519-
version "0.6.5"
4520-
resolved "https://registry.yarnpkg.com/focus-lock/-/focus-lock-0.6.5.tgz#f6eb37832a9b1b205406175f5277396a28c0fce1"
4521-
integrity sha512-i/mVBOoa9o+tl+u9owOJUF8k8L85odZNIsctB+JAK2HFT8jckiBwmk+3uydlm6FN8czgnkIwQtBv6yyAbrzXjw==
4518+
focus-lock@^0.6.6:
4519+
version "0.6.6"
4520+
resolved "https://registry.yarnpkg.com/focus-lock/-/focus-lock-0.6.6.tgz#98119a755a38cfdbeda0280eaa77e307eee850c7"
4521+
integrity sha512-Dx69IXGCq1qsUExWuG+5wkiMqVM/zGx/reXSJSLogECwp3x6KeNQZ+NAetgxEFpnC41rD8U3+jRCW68+LNzdtw==
45224522

45234523
follow-redirects@^1.0.0:
45244524
version "1.5.9"
@@ -8584,13 +8584,13 @@ react-dom@^16.8.6:
85848584
prop-types "^15.6.2"
85858585
scheduler "^0.13.6"
85868586

8587-
react-focus-lock@^2.2.0:
8588-
version "2.2.0"
8589-
resolved "https://registry.yarnpkg.com/react-focus-lock/-/react-focus-lock-2.2.0.tgz#8eb17dfb4c51e1b0a514bd0d4555208e46715deb"
8590-
integrity sha512-0Km5cKst2pQJqaE1ctNzkSH/ev9sw7Xl24OfY3U9PhVb4/d9F9qwWsiRd9KQ5lOSKeUpLlp/NP8l+FE+LM/e0A==
8587+
react-focus-lock@^2.2.1:
8588+
version "2.2.1"
8589+
resolved "https://registry.yarnpkg.com/react-focus-lock/-/react-focus-lock-2.2.1.tgz#1d12887416925dc53481914b7cedd39494a3b24a"
8590+
integrity sha512-47g0xYcCTZccdzKRGufepY8oZ3W1Qg+2hn6u9SHZ0zUB6uz/4K4xJe7yYFNZ1qT6m+2JDm82F6QgKeBTbjW4PQ==
85918591
dependencies:
85928592
"@babel/runtime" "^7.0.0"
8593-
focus-lock "^0.6.5"
8593+
focus-lock "^0.6.6"
85948594
prop-types "^15.6.2"
85958595
react-clientside-effect "^1.2.2"
85968596
use-callback-ref "^1.2.1"
@@ -8631,10 +8631,10 @@ react-remove-scroll-bar@^2.0.0:
86318631
react-style-singleton "^2.0.0"
86328632
tslib "^1.0.0"
86338633

8634-
react-remove-scroll@^2.1.1:
8635-
version "2.1.1"
8636-
resolved "https://registry.yarnpkg.com/react-remove-scroll/-/react-remove-scroll-2.1.1.tgz#8149d91bbc507ba06495cc9e18edb4c799a6654c"
8637-
integrity sha512-5FE6/hUw8ajzRpbeJDQ2XXQ1+u5ox6JBLNl6T8o5cBJ64i4KARgxyToJnm8g4EptjBKnoQQwUYkHzxCOZWbynw==
8634+
react-remove-scroll@^2.2.0:
8635+
version "2.2.0"
8636+
resolved "https://registry.yarnpkg.com/react-remove-scroll/-/react-remove-scroll-2.2.0.tgz#f42e6a4791ebfcce2c96f970d24deb1399fa9550"
8637+
integrity sha512-bT29xAkNuhS2tnsxhLNJrmmb6Rn8VsnlOfSoRaKdKi90DbhRcQfJ9vHG1TtgfkCP+rx059vCGIScPZaCWsyIKA==
86388638
dependencies:
86398639
react-remove-scroll-bar "^2.0.0"
86408640
react-style-singleton "^2.0.0"

0 commit comments

Comments
 (0)