Skip to content

Commit ea15dfe

Browse files
authored
Fix nested selectors extending too high (#481)
* bug: Fixed elements being excluded when the component that matches an exclusion is actually above the zoom-pan-pinch element in the DOM * chore: code style
1 parent 2b436bd commit ea15dfe

4 files changed

Lines changed: 20 additions & 5 deletions

File tree

src/components/transform-component/transform-component.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import React, { useContext, useEffect, useRef } from "react";
33

44
import { Context } from "../transform-wrapper/transform-wrapper";
5+
import { baseClasses } from "../../constants/state.constants";
56

67
import styles from "./transform-component.module.css";
78

@@ -45,13 +46,13 @@ export const TransformComponent: React.FC<Props> = ({
4546
<div
4647
{...wrapperProps}
4748
ref={wrapperRef}
48-
className={`react-transform-wrapper ${styles.wrapper} ${wrapperClass}`}
49+
className={`${baseClasses.wrapperClass} ${styles.wrapper} ${wrapperClass}`}
4950
style={wrapperStyle}
5051
>
5152
<div
5253
{...contentProps}
5354
ref={contentRef}
54-
className={`react-transform-component ${styles.content} ${contentClass}`}
55+
className={`${baseClasses.contentClass} ${styles.content} ${contentClass}`}
5556
style={contentStyle}
5657
>
5758
{children}

src/constants/state.constants.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LibrarySetup, ReactZoomPanPinchState } from "../models/context.model";
1+
import { LibrarySetup, ReactZoomPanPinchState, ReactZoomPanPinchBaseClasses } from "../models/context.model";
22

33
export const initialState: ReactZoomPanPinchState = {
44
previousScale: 1,
@@ -76,3 +76,8 @@ export const initialSetup: LibrarySetup = {
7676
equalToMove: true,
7777
},
7878
};
79+
80+
export const baseClasses: ReactZoomPanPinchBaseClasses = {
81+
wrapperClass: "react-transform-wrapper",
82+
contentClass: "react-transform-component",
83+
};

src/models/context.model.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,8 @@ export type LibrarySetup = Pick<
198198
| "customTransform"
199199
>
200200
>;
201+
202+
export type ReactZoomPanPinchBaseClasses = {
203+
wrapperClass: string;
204+
contentClass: string;
205+
};

src/utils/helpers.utils.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
import { baseClasses } from "../constants/state.constants";
2+
3+
const matchPrefix = `.${baseClasses.wrapperClass}`;
4+
15
export const isExcludedNode = (
26
node: HTMLElement,
37
excluded: string[],
48
): boolean => {
5-
return excluded.some((exclude) =>
6-
node.matches(`${exclude}, .${exclude}, ${exclude} *, .${exclude} *`),
9+
return excluded.some((exclude) =>
10+
node.matches(`${matchPrefix} ${exclude}, ${matchPrefix} .${exclude}, ${matchPrefix} ${exclude} *, ${matchPrefix} .${exclude} *`),
711
);
812
};
913

0 commit comments

Comments
 (0)