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

stacklok / codegate-ui / 13903674755

17 Mar 2025 03:42PM UTC 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-radio-group.tsx
1
import { FieldError, RadioGroup } from '@stacklok/ui-kit'
2
import type { ComponentProps } from 'react'
3
import { useController, useFormContext } from 'react-hook-form'
4

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

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

18
  const {
19
    field: {
20
      disabled: isDisabledByForm,
21
      name,
22
      onBlur,
23
      onChange,
24
      ref,
25
      value = '',
×
26
    },
27
    fieldState: { error, invalid },
NEW
28
  } = useController({
×
29
    control,
30
    defaultValue: props.value ?? props.defaultValue,
×
31
    name: props.name,
32
  })
33

34
  return (
35
    <RadioGroup
36
      {...props}
37
      defaultValue={value}
38
      isDisabled={isDisabledByForm || props.isDisabled}
×
39
      isInvalid={invalid}
40
      name={name}
41
      onBlur={onBlur}
42
      onChange={(k) => {
NEW
43
        onChange(k)
×
NEW
44
        props.onChange?.(k)
×
45
      }}
46
      ref={ref}
47
      value={undefined} // react-hook-form relies on uncontrolled component
48
      validationBehavior="aria" // Let react-hook-form handle validation
49
    >
50
      {(renderProps) => {
51
        return (
52
          <>
53
            {typeof children === 'function' ? children(renderProps) : children}
×
54
            <FieldError>{error?.message}</FieldError>
55
          </>
56
        )
57
      }}
58
    </RadioGroup>
59
  )
60
}
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