• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

react-ui-org / react-ui / 12711508427

10 Jan 2025 02:35PM CUT coverage: 91.979% (-0.1%) from 92.074%
12711508427

Pull #582

github

web-flow
Merge 275469d60 into d3264dd94
Pull Request #582: Add controlled popover

813 of 891 branches covered (91.25%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

735 of 792 relevant lines covered (92.8%)

72.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

35.71
/src/components/ScrollView/_hooks/useScrollPositionHook.js
1
import {
2
  useLayoutEffect,
3
  useRef,
4
} from 'react';
5
import { getElementsPositionDifference } from '../_helpers/getElementsPositionDifference';
6

7
export const useScrollPosition = (effect, dependencies, contentEl, viewportEl, wait) => {
6✔
8
  const throttleTimeout = useRef(null);
28✔
9

10
  const callBack = (wasDelayed = false) => {
28!
11
    effect(getElementsPositionDifference(contentEl, viewportEl));
×
12

13
    if (wasDelayed) {
×
14
      throttleTimeout.current = null;
×
15
    }
16
  };
17

18
  useLayoutEffect(() => {
28✔
19
    const viewport = viewportEl.current;
28✔
20

21
    const handleScroll = () => {
28✔
22
      if (wait) {
×
23
        if (throttleTimeout.current === null) {
×
24
          throttleTimeout.current = setTimeout(callBack, wait, true);
×
25
        }
26
      } else {
27
        callBack();
×
28
      }
29
    };
30

31
    viewport.addEventListener('scroll', handleScroll);
28✔
32

33
    return () => {
28✔
34
      clearTimeout(throttleTimeout.current);
28✔
35
      viewport.removeEventListener('scroll', handleScroll);
28✔
36
    };
37
  }, dependencies); // eslint-disable-line react-hooks/exhaustive-deps
38
};
39

40
export default useScrollPosition;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc