1
1
import {
2
2
Autocomplete ,
3
3
AutocompleteProps ,
4
+ createFilterOptions ,
5
+ FilterOptionsState ,
4
6
FormControl ,
5
7
FormHelperText ,
6
8
TextField ,
@@ -23,7 +25,11 @@ interface ComboBoxProps {
23
25
24
26
type AutoCompleteComboBox = Omit <
25
27
AutocompleteProps < AutocompleteValue , false , false , false > ,
26
- 'options' | 'renderInput'
28
+ | 'options'
29
+ | 'renderInput'
30
+ | 'getOptionLabel'
31
+ | 'isOptionEqualToValue'
32
+ | 'filterOptions'
27
33
> ;
28
34
29
35
const compareOptionLabels = ( a : ComboBoxOption , b : ComboBoxOption ) => {
@@ -47,6 +53,14 @@ const isOptionEqualToValue = (
47
53
}
48
54
} ;
49
55
56
+ const filterOptions : (
57
+ options : Array < AutocompleteValue > ,
58
+ state : FilterOptionsState < AutocompleteValue >
59
+ ) => Array < AutocompleteValue > = createFilterOptions ( {
60
+ matchFrom : 'start' ,
61
+ trim : true ,
62
+ } ) ;
63
+
50
64
export const valueAsOption = ( value : string ) => ( {
51
65
value : value ,
52
66
label : value ,
@@ -74,6 +88,7 @@ export const ComboBox = ({
74
88
getOptionLabel = { getOptionLabel }
75
89
isOptionEqualToValue = { isOptionEqualToValue }
76
90
options = { values }
91
+ filterOptions = { filterOptions }
77
92
renderInput = { ( params ) => (
78
93
< TextField
79
94
{ ...params }
@@ -119,6 +134,7 @@ export const LabeledComboBox = ({
119
134
getOptionLabel = { getOptionLabel }
120
135
isOptionEqualToValue = { isOptionEqualToValue }
121
136
options = { values }
137
+ filterOptions = { filterOptions }
122
138
renderInput = { ( params ) => (
123
139
< TextField
124
140
{ ...params }
0 commit comments