1
1
import React , { useMemo } from 'react' ;
2
2
3
- import { Combobox as EvergreenCombobox , FormField } from 'evergreen-ui' ;
3
+ import { Combobox as EvergreenCombobox , ComboboxProps as EvergreenComboboxProps , FormField , FormFieldProps } from 'evergreen-ui' ;
4
4
5
5
import 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' ;
10
7
11
8
export interface ComboBoxItem extends AnyObject {
12
- value ?: any ;
13
- label : string ;
9
+ value ?: any ;
10
+ label : string ;
14
11
}
15
12
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 [ ] ;
20
20
}
21
21
22
22
const ComboBox : React . FC < ComboBoxProps > = ( props ) => {
23
- const {
24
- id,
23
+ const { id,
25
24
input,
26
25
meta,
27
26
isDisabled,
@@ -31,10 +30,10 @@ const ComboBox: React.FC<ComboBoxProps> = (props) => {
31
30
description,
32
31
inputProps,
33
32
...rest
34
- } = useFieldApi ( props ) ;
33
+ } = useFieldApi ( props ) as ComboBoxProps ;
35
34
36
35
const selectedItem = useMemo ( ( ) => {
37
- return options . find ( ( item : ComboBoxItem ) => item . value === input . value ) ;
36
+ return options . find ( ( item : ComboBoxItem ) => item . value === input . value ) ?? null ;
38
37
} , [ input . value , options ] ) ;
39
38
40
39
return (
0 commit comments