Skip to content

Commit

Permalink
fix: Skip shadow root when traversing up the dom tree
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed Jul 4, 2021
1 parent 2bff2f1 commit eb6a5e7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-remove-scroll",
"version": "2.4.2",
"version": "2.4.3",
"description": "Disables scroll outside of `children` node.",
"main": "dist/es5/index.js",
"scripts": {
Expand Down
28 changes: 14 additions & 14 deletions src/handleScroll.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Axis } from './types';
import {Axis} from './types';

const elementCouldBeVScrolled = (node: HTMLElement): boolean => {
const styles = window.getComputedStyle(node);
Expand Down Expand Up @@ -27,7 +27,7 @@ export const locationCouldBeScrolled = (
let current = node;
do {
// Skip over shadow root
if (window.ShadowRoot && current instanceof window.ShadowRoot) {
if (typeof ShadowRoot !== "undefined" && current instanceof ShadowRoot) {
current = current.host as HTMLElement;
}

Expand All @@ -45,15 +45,15 @@ export const locationCouldBeScrolled = (
};

const getVScrollVariables = ({
scrollTop,
scrollHeight,
clientHeight
}: HTMLElement) => [scrollTop, scrollHeight, clientHeight];
scrollTop,
scrollHeight,
clientHeight
}: HTMLElement) => [scrollTop, scrollHeight, clientHeight];
const getHScrollVariables = ({
scrollLeft,
scrollWidth,
clientWidth
}: HTMLElement) => [scrollLeft, scrollWidth, clientWidth];
scrollLeft,
scrollWidth,
clientWidth
}: HTMLElement) => [scrollLeft, scrollWidth, clientWidth];

const elementCouldBeScrolled = (axis: Axis, node: HTMLElement): boolean =>
axis === 'v' ? elementCouldBeVScrolled(node) : elementCouldBeHScrolled(node);
Expand Down Expand Up @@ -93,10 +93,10 @@ export const handleScroll = (
target = target.parentNode as any;
} while (
// portaled content
(!targetInLock && target !== document.body) ||
// self content
(targetInLock && (endTarget.contains(target) || endTarget === target))
);
(!targetInLock && target !== document.body) ||
// self content
(targetInLock && (endTarget.contains(target) || endTarget === target))
);

if (
isDeltaPositive &&
Expand Down

0 comments on commit eb6a5e7

Please sign in to comment.