-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fixed issue where Field would not infer correct change handler
- Loading branch information
1 parent
5a55000
commit 654ad18
Showing
5 changed files
with
82 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@saas-ui/forms': patch | ||
'@saas-ui/react': patch | ||
--- | ||
|
||
Fixed issue where Field would not infer correct onChange handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import * as React from 'react' | ||
|
||
import { | ||
DefaultFields, | ||
Field, | ||
FieldProps, | ||
Select, | ||
SelectButton, | ||
SelectList, | ||
SelectProps, | ||
createField, | ||
} from '../src' | ||
import { forwardRef } from '@chakra-ui/react' | ||
import { expectTypeOf } from 'vitest' | ||
|
||
export const CustomField = createField<SelectProps>( | ||
forwardRef((props, ref) => { | ||
return ( | ||
<Select ref={ref} {...props}> | ||
<SelectButton /> | ||
<SelectList /> | ||
</Select> | ||
) | ||
}), | ||
{ | ||
isControlled: true, | ||
} | ||
) | ||
|
||
type PropTypes = React.ComponentProps<typeof CustomField> | ||
|
||
test('should have correct event handler type', async () => { | ||
expectTypeOf<PropTypes['onChange']>().toEqualTypeOf< | ||
((value: string | string[]) => void) | undefined | ||
>() | ||
}) | ||
|
||
const selectProps: FieldProps = { | ||
name: 'test', | ||
type: 'select', | ||
} | ||
|
||
const inputProps: FieldProps = { | ||
name: 'test', | ||
type: 'text', | ||
} | ||
|
||
test('should have correct event handler type on Field', async () => { | ||
expectTypeOf<(typeof selectProps)['onChange']>().toEqualTypeOf< | ||
((value: string | string[]) => void) | undefined | ||
>() | ||
|
||
expectTypeOf<(typeof inputProps)['onChange']>().toEqualTypeOf< | ||
React.ChangeEventHandler<HTMLInputElement> | undefined | ||
>() | ||
}) |