File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
src/Shared/Hooks/useStickyEvent Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -37,7 +37,12 @@ const useStickyEvent = <T extends HTMLElement = HTMLDivElement>({
37
37
return noop
38
38
}
39
39
40
- // NOTE: these values are being used as closures
40
+ // The sentinel is a div used to detect when the sticky element is stuck.
41
+ // It is taller than the sticky element's top offset, ensuring it overflows
42
+ // the container when the sticky element sticks to the top.
43
+ // Using IntersectionObserver, we observe both the sticky element and the sentinel.
44
+ // When the sentinel is not fully in view, isIntersecting is false,
45
+ // indicating the sticky element is stuck given it is fully in view.
41
46
let previousStuckState : boolean
42
47
let hasSentinelLeftView : boolean
43
48
let hasHeaderLeftView : boolean
@@ -49,6 +54,10 @@ const useStickyEvent = <T extends HTMLElement = HTMLDivElement>({
49
54
entries . forEach ( ( entry ) => {
50
55
switch ( entry . target . id ) {
51
56
case sentinelId :
57
+ // NOTE: Since the threshold is set to 1.0, isIntersecting will be
58
+ // true only when the target element is fully within the container
59
+ // (root). If even a single pixel of the target element is outside
60
+ // the container, isIntersecting will be false.
52
61
hasSentinelLeftView = ! entry . isIntersecting
53
62
break
54
63
default :
You can’t perform that action at this time.
0 commit comments