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

stacklok / codegate-ui / 13903674755

17 Mar 2025 03:42PM CUT coverage: 61.874% (-4.6%) from 66.452%
13903674755

Pull #345

github

web-flow
Merge ce2550358 into 5d463ef04
Pull Request #345: feat: react-hook-form field array for provider muxes

443 of 798 branches covered (55.51%)

Branch coverage included in aggregate %.

63 of 93 new or added lines in 21 files covered. (67.74%)

50 existing lines in 4 files now uncovered.

904 of 1379 relevant lines covered (65.55%)

36.88 hits per line

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

0.0
/src/features/workspace/components/tmp/form-checkbox-group.tsx
1
import { CheckboxGroup, FieldError } from '@stacklok/ui-kit'
2
import type { ComponentProps } from 'react'
3
import { useController, useFormContext } from 'react-hook-form'
4

5
/**
6
 * A `FormCheckboxGroup` connects a `CheckboxGroup` to a `Form` component using `react-hook-form`.
7
 *
8
 * [React Aria Documentation](https://react-spectrum.adobe.com/react-aria/CheckboxGroup.html)
9
 */
10
export function FormCheckboxGroup({
11
  children,
12
  ...props
13
}: ComponentProps<typeof CheckboxGroup>) {
NEW
14
  if (props.name == null)
×
NEW
15
    throw new Error('FormCheckboxGroup requires a name prop')
×
16

NEW
17
  const { control } = useFormContext()
×
18

19
  const {
20
    field: { disabled: isDisabledByForm, name, onBlur, onChange, ref, value },
21
    fieldState: { error, invalid },
NEW
22
  } = useController({
×
23
    control,
24
    defaultValue: props.value ?? props.defaultValue ?? [],
×
25
    name: props.name,
26
  })
27

28
  return (
29
    <CheckboxGroup
30
      {...props}
31
      isDisabled={isDisabledByForm || props.isDisabled}
×
32
      isInvalid={invalid}
33
      name={name}
34
      onBlur={onBlur}
35
      onChange={(k) => {
NEW
36
        onChange(k)
×
NEW
37
        props.onChange?.(k)
×
38
      }}
39
      ref={ref}
40
      defaultValue={value}
41
      validationBehavior="aria" // Let React Hook Form handle validation instead of the browser.
42
    >
43
      {(renderProps) => {
44
        return (
45
          <>
46
            {typeof children === 'function' ? children(renderProps) : children}
×
47
            <FieldError>{error?.message}</FieldError>
48
          </>
49
        )
50
      }}
51
    </CheckboxGroup>
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