forked from clauderic/dnd-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getScrollableAncestors.ts
34 lines (26 loc) · 976 Bytes
/
getScrollableAncestors.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { isScrollable } from './isScrollable';
import { isFixed } from '../position/isFixed'
export function getScrollableAncestors(element: Node | null): Element[] {
const scrollParents: Element[] = [];
function findScrollableAncestors(node: Node | null): Element[] {
if (!node) {
return scrollParents;
}
if (node instanceof Document && node.scrollingElement != null) {
scrollParents.push(node.scrollingElement);
return scrollParents;
}
if (!(node instanceof HTMLElement) || node instanceof SVGElement) {
return scrollParents;
}
if (isScrollable(node)) {
// crazy stupid hotfix for positioning issue under fixed scroll ancestors. get offsetTop of the first ancestor only(!)
if (node && isFixed(node)) {
return [node]
}
scrollParents.push(node);
}
return findScrollableAncestors(node.parentNode);
}
return element ? findScrollableAncestors(element) : scrollParents;
}