Skip to content

Commit

Permalink
fix: UserChange/InputProps
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerlinsley committed Apr 27, 2023
1 parent 4e7ff05 commit 5b7c6ce
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 13 deletions.
File renamed without changes.
14 changes: 7 additions & 7 deletions docs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
},
Expand All @@ -31,7 +31,7 @@
"children": [
{
"label": "Important Defaults",
"to": "core/guides/important-defaults"
"to": "guides/important-defaults"
}
]
},
Expand All @@ -40,11 +40,11 @@
"children": [
{
"label": "FormApi",
"to": "core/reference/formApi"
"to": "reference/formApi"
},
{
"label": "FieldApi",
"to": "core/reference/fieldApi"
"to": "reference/fieldApi"
}
]
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 20 additions & 2 deletions docs/core/reference/fieldApi.md → docs/reference/fieldApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>`
Expand All @@ -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.
Expand Down
File renamed without changes.
File renamed without changes.
20 changes: 16 additions & 4 deletions packages/form-core/src/FieldApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 5b7c6ce

Please sign in to comment.