11import React , { useMemo } from 'react' ;
22
3- import { Combobox as EvergreenCombobox , FormField } from 'evergreen-ui' ;
3+ import { Combobox as EvergreenCombobox , ComboboxProps as EvergreenComboboxProps , FormField , FormFieldProps } from 'evergreen-ui' ;
44
55import useFieldApi from '@data-driven-forms/react-form-renderer/use-field-api' ;
6- import {
7- AnyObject ,
8- UseFieldApiProps ,
9- } from '@data-driven-forms/react-form-renderer' ;
6+ import { AnyObject , UseFieldApiProps } from '@data-driven-forms/react-form-renderer' ;
107
118export interface ComboBoxItem extends AnyObject {
12- value ?: any ;
13- label : string ;
9+ value ?: any ;
10+ label : string ;
1411}
1512
16- export interface ComboBoxProps extends UseFieldApiProps < string > {
17- name : string ;
18- isRequired ?: boolean ;
19- options : ComboBoxItem [ ] ;
13+ export interface ComboBoxProps
14+ extends UseFieldApiProps < string > ,
15+ Omit < EvergreenComboboxProps , 'selectedItem' | 'onChange' | 'disabled' | 'items' | 'itemToString' > ,
16+ Pick < FormFieldProps , 'label' | 'description' > {
17+ name : string ;
18+ isRequired ?: boolean ;
19+ options : ComboBoxItem [ ] ;
2020}
2121
2222const ComboBox : React . FC < ComboBoxProps > = ( props ) => {
23- const {
24- id,
23+ const { id,
2524 input,
2625 meta,
2726 isDisabled,
@@ -31,10 +30,10 @@ const ComboBox: React.FC<ComboBoxProps> = (props) => {
3130 description,
3231 inputProps,
3332 ...rest
34- } = useFieldApi ( props ) ;
33+ } = useFieldApi ( props ) as ComboBoxProps ;
3534
3635 const selectedItem = useMemo ( ( ) => {
37- return options . find ( ( item : ComboBoxItem ) => item . value === input . value ) ;
36+ return options . find ( ( item : ComboBoxItem ) => item . value === input . value ) ?? null ;
3837 } , [ input . value , options ] ) ;
3938
4039 return (
0 commit comments