Skip to content

Commit 3cc41f3

Browse files
authored
Fix issue with elements not triggering intersection when within positioned: fixed element (#280)
1 parent 5f0737e commit 3cc41f3

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/content/actions/scroll.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ declare global {
1515
}
1616
}
1717

18-
let lastScrollContainer: HTMLElement | undefined;
18+
let lastScrollContainer: Element | undefined;
1919
let lastScrollFactor: number;
2020

2121
interface ScrollOptions {
@@ -284,7 +284,7 @@ export function snapScroll(
284284
export function scroll(options: ScrollOptions) {
285285
const { dir, target } = options;
286286
let factor = options.factor;
287-
let scrollContainer: HTMLElement | undefined;
287+
let scrollContainer: Element | undefined;
288288
const direction =
289289
dir === "left" || dir === "right" ? "horizontal" : "vertical";
290290

src/content/utils/getUserScrollableContainer.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
const containersCache: Map<Element, HTMLElement> = new Map();
22

3+
/**
4+
* Given an Element return the Element that contains it and might scroll it. It
5+
* doesn't necessarily mean that the container scrolls, but if it does, the
6+
* given element would scroll with it.
7+
*/
38
export function getUserScrollableContainer(
49
element: Element,
510
direction?: "vertical" | "horizontal"
6-
): HTMLElement {
11+
) {
712
const elementPosition = window.getComputedStyle(element).position;
813

914
const checked = [];
@@ -16,6 +21,10 @@ export function getUserScrollableContainer(
1621
const { position, overflowX, overflowY } = window.getComputedStyle(current);
1722
const { scrollWidth, clientWidth, scrollHeight, clientHeight } = current;
1823

24+
if (position === "fixed") {
25+
return current;
26+
}
27+
1928
// If the element is position: absolute we need to ignore any element with
2029
// position: static as our element won't scroll with that container
2130
if (elementPosition === "absolute" && position === "static") {

src/typings/ElementWrapper.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export interface ElementWrapper {
2020

2121
// These properties are only needed for hintables
2222
intersectionObserver?: BoundedIntersectionObserver;
23-
userScrollableContainer?: HTMLElement;
23+
userScrollableContainer?: Element;
2424
effectiveBackgroundColor?: string;
2525
hint?: Hint;
2626

0 commit comments

Comments
 (0)