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

atomicpages / pretty-checkbox-react / 9820775925

06 Jul 2024 04:56PM UTC coverage: 100.0%. Remained the same
9820775925

push

github

atomicpages
feat: support ESM and move to tsup

67 of 67 branches covered (100.0%)

Branch coverage included in aggregate %.

69 of 69 new or added lines in 15 files covered. (100.0%)

171 of 171 relevant lines covered (100.0%)

11.42 hits per line

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

100.0
/src/components/checkbox/useIndeterminate.ts
1
import * as React from "react";
3✔
2

3
import type { UseCheckboxState } from "./useCheckboxState";
4

5
export type UseIndeterminateOptions = {
6
  checked?: boolean;
7
  state?: UseCheckboxState["state"];
8
  indeterminate?: boolean;
9
};
10

11
export const useIndeterminate = ({
3✔
12
  checked,
13
  state,
14
  indeterminate: indeterminateFromProps,
15
}: UseIndeterminateOptions): {
16
  ref: React.MutableRefObject<HTMLInputElement>;
17
  "aria-checked": React.AriaAttributes["aria-checked"];
18
} => {
19
  const [indeterminate, setStatus] = React.useState(false);
35✔
20
  const ref = React.useRef<HTMLInputElement>(
35✔
21
    null,
22
  ) as React.MutableRefObject<HTMLInputElement>;
23

24
  React.useEffect(() => {
35✔
25
    if (state !== undefined && ref.current) {
24✔
26
      setStatus(state === "indeterminate");
19✔
27
    }
28
  }, [state]);
29

30
  // if a prop is passed mark the indeterminate state
31
  // we should check to ensure state isn't set to indeterminate
32
  // since we don't want ot clobber the state value if
33
  // it is defined.
34
  React.useEffect(() => {
35✔
35
    if (
25✔
36
      state !== "indeterminate" &&
69✔
37
      ref.current &&
38
      typeof indeterminateFromProps !== "undefined"
39
    ) {
40
      ref.current.checked = indeterminateFromProps;
1✔
41

42
      // fix needs to come from pretty-checkbox
43
      // ref.current.indeterminate = indeterminateFromProps;
44

45
      setStatus(indeterminateFromProps);
1✔
46
    }
47
  }, [indeterminateFromProps, state]);
48

49
  return {
35✔
50
    ref,
51
    "aria-checked": indeterminate ? "mixed" : checked,
35✔
52
  };
53
};
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