Skip to content

Commit

Permalink
fix: correct behavior in shadow dom
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed May 12, 2024
1 parent 6a25122 commit ea7a398
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## [2.5.9](https://github.com/theKashey/react-remove-scroll/compare/v2.5.8...v2.5.9) (2024-03-16)

## [2.5.8](https://github.com/theKashey/react-remove-scroll/compare/v2.5.7...v2.5.8) (2024-03-16)

### Bug Fixes
Expand Down
22 changes: 13 additions & 9 deletions src/handleScroll.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import {Axis} from './types';
import { Axis } from './types';

const alwaysContainsScroll = (node: HTMLElement): boolean =>
const alwaysContainsScroll = (node: Element): boolean =>
// textarea will always _contain_ scroll inside self. It only can be hidden
node.tagName === 'TEXTAREA';

const elementCanBeScrolled = (node: HTMLElement, overflow: 'overflowX' | 'overflowY'): boolean => {
if (!(node instanceof HTMLElement)) return false;

const elementCanBeScrolled = (node: Element, overflow: 'overflowX' | 'overflowY'): boolean => {
if (!(node instanceof Element)) {
return false;
}

const styles = window.getComputedStyle(node);

return (
Expand All @@ -33,9 +35,9 @@ export const locationCouldBeScrolled = (axis: Axis, node: HTMLElement): boolean
const isScrollable = elementCouldBeScrolled(axis, current);

if (isScrollable) {
const [, s, d] = getScrollVariables(axis, current);
const [, scrollHeight, clientHeight] = getScrollVariables(axis, current);

if (s > d) {
if (scrollHeight > clientHeight) {
return true;
}
}
Expand All @@ -46,12 +48,14 @@ export const locationCouldBeScrolled = (axis: Axis, node: HTMLElement): boolean
return false;
};

const getVScrollVariables = ({ scrollTop, scrollHeight, clientHeight }: HTMLElement) => [
type SV = [scrollTop: number, scrollHeight: number, clientHeight: number];

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

0 comments on commit ea7a398

Please sign in to comment.