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

glideapps / glide-data-grid / 7316502082

24 Dec 2023 07:35PM CUT coverage: 90.577%. Remained the same
7316502082

Pull #830

github

jassmith
Allow specifying label and value independently in dropdown cell
Pull Request #830: Allow specifying label and value independently in dropdown cell

2590 of 3242 branches covered (0.0%)

15745 of 17383 relevant lines covered (90.58%)

3079.34 hits per line

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

57.38
/packages/core/src/internal/data-grid-overlay-editor/use-stay-on-screen.ts
1
import * as React from "react";
1✔
2

1✔
3
function useRefState(): [HTMLElement | undefined, React.RefCallback<HTMLElement | null>] {
31✔
4
    const [refState, setRefState] = React.useState<HTMLElement | null>();
31✔
5
    return [refState ?? undefined, setRefState];
31✔
6
}
31✔
7

1✔
8
interface StayOnScreen {
1✔
9
    ref: React.RefCallback<HTMLElement | null>;
1✔
10
    style: React.CSSProperties;
1✔
11
}
1✔
12

1✔
13
export function useStayOnScreen(): StayOnScreen {
1✔
14
    const [ref, setRef] = useRefState();
31✔
15
    const [xOffset, setXOffset] = React.useState(0);
31✔
16
    const [isIntersecting, setIsIntersecting] = React.useState(true);
31✔
17

31✔
18
    React.useLayoutEffect(() => {
31✔
19
        if (ref === undefined) return;
24✔
20
        if (!("IntersectionObserver" in window)) return;
12!
21

×
22
        const observer = new IntersectionObserver(
×
23
            ents => {
×
24
                if (ents.length === 0) return;
×
25
                setIsIntersecting(ents[0].isIntersecting);
×
26
            },
×
27
            { threshold: 1 }
×
28
        );
×
29
        observer.observe(ref);
×
30

×
31
        return () => observer.disconnect();
×
32
    }, [ref]);
31✔
33

31✔
34
    React.useEffect(() => {
31✔
35
        if (isIntersecting || ref === undefined) return;
24!
36

×
37
        let rafHandle: number | undefined;
×
38
        const fn = () => {
×
39
            const { right: refRight } = ref.getBoundingClientRect();
×
40

×
41
            setXOffset(cv => Math.min(cv + window.innerWidth - refRight - 10, 0));
×
42
            rafHandle = requestAnimationFrame(fn);
×
43
        };
×
44

×
45
        rafHandle = requestAnimationFrame(fn);
×
46
        return () => {
×
47
            if (rafHandle !== undefined) {
×
48
                cancelAnimationFrame(rafHandle);
×
49
            }
×
50
        };
×
51
    }, [ref, isIntersecting]);
31✔
52

31✔
53
    const style = React.useMemo(() => {
31✔
54
        return { transform: `translateX(${xOffset}px)` };
12✔
55
    }, [xOffset]);
31✔
56

31✔
57
    return {
31✔
58
        ref: setRef,
31✔
59
        style,
31✔
60
    };
31✔
61
}
31✔
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