Skip to content

Commit

Permalink
Fix nested selectors extending too high (#481)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bigbadwofl authored Jun 27, 2024
1 parent 2b436bd commit ea15dfe
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/components/transform-component/transform-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import React, { useContext, useEffect, useRef } from "react";

import { Context } from "../transform-wrapper/transform-wrapper";
import { baseClasses } from "../../constants/state.constants";

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

Expand Down Expand Up @@ -45,13 +46,13 @@ export const TransformComponent: React.FC<Props> = ({
<div
{...wrapperProps}
ref={wrapperRef}
className={`react-transform-wrapper ${styles.wrapper} ${wrapperClass}`}
className={`${baseClasses.wrapperClass} ${styles.wrapper} ${wrapperClass}`}
style={wrapperStyle}
>
<div
{...contentProps}
ref={contentRef}
className={`react-transform-component ${styles.content} ${contentClass}`}
className={`${baseClasses.contentClass} ${styles.content} ${contentClass}`}
style={contentStyle}
>
{children}
Expand Down
7 changes: 6 additions & 1 deletion src/constants/state.constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LibrarySetup, ReactZoomPanPinchState } from "../models/context.model";
import { LibrarySetup, ReactZoomPanPinchState, ReactZoomPanPinchBaseClasses } from "../models/context.model";

export const initialState: ReactZoomPanPinchState = {
previousScale: 1,
Expand Down Expand Up @@ -76,3 +76,8 @@ export const initialSetup: LibrarySetup = {
equalToMove: true,
},
};

export const baseClasses: ReactZoomPanPinchBaseClasses = {
wrapperClass: "react-transform-wrapper",
contentClass: "react-transform-component",
};
5 changes: 5 additions & 0 deletions src/models/context.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,8 @@ export type LibrarySetup = Pick<
| "customTransform"
>
>;

export type ReactZoomPanPinchBaseClasses = {
wrapperClass: string;
contentClass: string;
};
8 changes: 6 additions & 2 deletions src/utils/helpers.utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { baseClasses } from "../constants/state.constants";

const matchPrefix = `.${baseClasses.wrapperClass}`;

export const isExcludedNode = (
node: HTMLElement,
excluded: string[],
): boolean => {
return excluded.some((exclude) =>
node.matches(`${exclude}, .${exclude}, ${exclude} *, .${exclude} *`),
return excluded.some((exclude) =>
node.matches(`${matchPrefix} ${exclude}, ${matchPrefix} .${exclude}, ${matchPrefix} ${exclude} *, ${matchPrefix} .${exclude} *`),
);
};

Expand Down

0 comments on commit ea15dfe

Please sign in to comment.