|
1 | 1 | import { ComponentProps } from 'react'; |
2 | | -import { |
3 | | - Controller, |
4 | | - ControllerRenderProps, |
5 | | - FieldPath, |
6 | | - FieldValues, |
7 | | -} from 'react-hook-form'; |
| 2 | +import { Controller, FieldPath, FieldValues } from 'react-hook-form'; |
8 | 3 | import { isNullish } from 'remeda'; |
9 | 4 |
|
10 | 5 | import { cn } from '@/lib/tailwind/utils'; |
11 | 6 |
|
12 | 7 | import { NumberInput } from '@/components/ui/number-input'; |
13 | 8 |
|
14 | 9 | import { useFormField } from '../form-field'; |
15 | | -import { FieldCommonProps } from '../form-field-controller'; |
| 10 | +import { FieldProps } from '../form-field-controller'; |
16 | 11 | import { FormFieldError } from '../form-field-error'; |
17 | 12 |
|
18 | 13 | export type FieldNumberProps< |
19 | 14 | TFieldValues extends FieldValues = FieldValues, |
20 | 15 | TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>, |
21 | | -> = FieldCommonProps<TFieldValues, TName> & { |
22 | | - type: 'number'; |
23 | | - containerProps?: ComponentProps<'div'>; |
24 | | - inCents?: boolean; |
25 | | -} & RemoveFromType< |
26 | | - Omit< |
27 | | - ComponentProps<typeof NumberInput>, |
28 | | - 'id' | 'aria-invalid' | 'aria-describedby' |
29 | | - >, |
30 | | - ControllerRenderProps |
31 | | - >; |
| 16 | +> = FieldProps< |
| 17 | + TFieldValues, |
| 18 | + TName, |
| 19 | + { |
| 20 | + type: 'number'; |
| 21 | + containerProps?: ComponentProps<'div'>; |
| 22 | + inCents?: boolean; |
| 23 | + } & ComponentProps<typeof NumberInput> |
| 24 | +>; |
32 | 25 |
|
33 | 26 | export const FieldNumber = < |
34 | 27 | TFieldValues extends FieldValues = FieldValues, |
@@ -91,6 +84,11 @@ export const FieldNumber = < |
91 | 84 | value={formatValue(value, 'from-cents')} |
92 | 85 | onValueChange={(value) => { |
93 | 86 | onChange(formatValue(value, 'to-cents')); |
| 87 | + rest.onValueChange?.(value); |
| 88 | + }} |
| 89 | + onBlur={(e) => { |
| 90 | + field.onBlur(); |
| 91 | + rest.onBlur?.(e); |
94 | 92 | }} |
95 | 93 | /> |
96 | 94 | <FormFieldError /> |
|
0 commit comments