fix: UserChange/InputProps

This commit is contained in:
Tanner Linsley
2023-04-27 13:27:20 -06:00
parent 4e7ff05abe
commit 5b7c6ce55d
14 changed files with 43 additions and 13 deletions

View File

@@ -10,19 +10,19 @@
"children": [
{
"label": "Overview",
"to": "core/overview"
"to": "overview"
},
{
"label": "Installation",
"to": "core/installation"
"to": "installation"
},
{
"label": "Comparison",
"to": "core/comparison"
"to": "comparison"
},
{
"label": "TypeScript",
"to": "core/typescript"
"to": "typescript"
}
]
},
@@ -31,7 +31,7 @@
"children": [
{
"label": "Important Defaults",
"to": "core/guides/important-defaults"
"to": "guides/important-defaults"
}
]
},
@@ -40,11 +40,11 @@
"children": [
{
"label": "FormApi",
"to": "core/reference/formApi"
"to": "reference/formApi"
},
{
"label": "FieldApi",
"to": "core/reference/fieldApi"
"to": "reference/fieldApi"
}
]
}

View File

@@ -110,9 +110,9 @@ A class representing the API for managing a form field.
- Gets a subfield instance.
- `validate(): Promise<any>`
- Validates the field value.
- `getChangeProps<T extends ChangeProps<any>>(props: T = {} as T): ChangeProps<TData> & Omit<T, keyof ChangeProps<TData>>`
- `getChangeProps<T extends UserChangeProps<any>>(props: T = {} as T): ChangeProps<TData> & Omit<T, keyof ChangeProps<TData>>`
- Gets the change and blur event handlers.
- `getInputProps<T extends InputProps>(props: T = {} as T): InputProps & Omit<T, keyof InputProps>`
- `getInputProps<T extends UserInputProps>(props: T = {} as T): InputProps & Omit<T, keyof InputProps>`
- Gets the input event handlers.
### `FieldState<TData>`
@@ -124,6 +124,24 @@ An object type representing the state of a field.
- `meta: FieldMeta`
- The current metadata of the field.
### `UserChangeProps<TData>`
An object type representing the change and blur event handlers for a field.
- `onChange?: (updater: Updater<TData>) => void`
- An optional function to further handle the change event.
- `onBlur?: (event: any) => void`
- An optional function to further handle the blur event.
### `UserInputProps`
An object type representing the input event handlers for a field.
- `onChange?: (event: any) => void`
- An optional function to further handle the change event.
- `onBlur?: (event: any) => void`
- An optional function to further handle the blur event.
### `ChangeProps<TData>`
An object type representing the change and blur event handlers for a field.

View File

@@ -31,16 +31,28 @@ export type FieldMeta = {
isValidating: boolean
}
export type ChangeProps<TData> = {
export type UserChangeProps<TData> = {
onChange?: (updater: Updater<TData>) => void
onBlur?: (event: any) => void
}
export type InputProps = {
export type UserInputProps = {
onChange?: (event: any) => void
onBlur?: (event: any) => void
}
export type ChangeProps<TData> = {
value: TData
onChange: (updater: Updater<TData>) => void
onBlur: (event: any) => void
}
export type InputProps = {
value: string
onChange: (event: any) => void
onBlur: (event: any) => void
}
export type FieldApiOptions<TData, TFormData> = RequiredByKey<
FieldOptions<TData, TFormData>,
'form'
@@ -332,7 +344,7 @@ export class FieldApi<TData, TFormData> {
return undefined
}
getChangeProps = <T extends ChangeProps<any>>(
getChangeProps = <T extends UserChangeProps<any>>(
props: T = {} as T,
): ChangeProps<TData> & Omit<T, keyof ChangeProps<TData>> => {
return {
@@ -350,7 +362,7 @@ export class FieldApi<TData, TFormData> {
} as ChangeProps<TData> & Omit<T, keyof ChangeProps<TData>>
}
getInputProps = <T extends InputProps>(
getInputProps = <T extends UserInputProps>(
props: T = {} as T,
): InputProps & Omit<T, keyof InputProps> => {
return {