@@ -5,7 +5,7 @@ import { useFieldApi } from '@data-driven-forms/react-form-renderer';
55import DataDrivenSelect from '@data-driven-forms/common/src/select' ;
66import fnToString from '@data-driven-forms/common/src/utils/fn-to-string' ;
77
8- import { Select as CarbonSelect , MultiSelect , SelectItem } from 'carbon-components-react' ;
8+ import { Select as CarbonSelect , MultiSelect , SelectItem , ComboBox } from 'carbon-components-react' ;
99import prepareProps from '../common/prepare-props' ;
1010
1111export const multiOnChange = ( input , simpleValue ) => ( { selectedItems } ) => {
@@ -165,8 +165,63 @@ ClearedSelect.propTypes = {
165165 isClearable : PropTypes . bool
166166} ;
167167
168+ const ClearedSelectSearchable = ( {
169+ isSearchable,
170+ isClearable,
171+ isDisabled,
172+ isMulti,
173+ invalidText,
174+ hideSelectedOptions,
175+ noOptionsMessage,
176+ onInputChange,
177+ options,
178+ isFetching,
179+ invalid,
180+ classNamePrefix,
181+ closeMenuOnSelect,
182+ originalOnChange,
183+ placeholder,
184+ labelText,
185+ ...rest
186+ } ) => (
187+ < ComboBox
188+ disabled = { isFetching }
189+ { ...rest }
190+ id = { rest . name }
191+ invalid = { Boolean ( invalidText ) }
192+ invalidText = { invalidText }
193+ initialSelectedItem = { rest . value }
194+ items = { options }
195+ placeholder = { placeholder }
196+ titleText = { labelText }
197+ onChange = { originalOnChange }
198+ />
199+ ) ;
200+
201+ ClearedSelectSearchable . propTypes = {
202+ invalidText : PropTypes . node ,
203+ hideSelectedOptions : PropTypes . any ,
204+ noOptionsMessage : PropTypes . any ,
205+ onInputChange : PropTypes . func ,
206+ options : PropTypes . array ,
207+ isFetching : PropTypes . bool ,
208+ invalid : PropTypes . oneOfType ( [ PropTypes . bool , PropTypes . node ] ) ,
209+ isMulti : PropTypes . bool ,
210+ classNamePrefix : PropTypes . any ,
211+ closeMenuOnSelect : PropTypes . any ,
212+ onChange : PropTypes . func ,
213+ originalOnChange : PropTypes . func ,
214+ carbonLabel : PropTypes . node ,
215+ placeholder : PropTypes . node ,
216+ isDisabled : PropTypes . bool ,
217+ isRequired : PropTypes . bool ,
218+ isSearchable : PropTypes . bool ,
219+ isClearable : PropTypes . bool ,
220+ labelText : PropTypes . string
221+ } ;
222+
168223const Select = ( props ) => {
169- const { isMulti, isSearchable, loadOptions, input, meta, validateOnMount, helperText, ...rest } = useFieldApi ( prepareProps ( props ) ) ;
224+ const { isMulti, isSearchable, isClearable , loadOptions, input, meta, validateOnMount, helperText, ...rest } = useFieldApi ( prepareProps ( props ) ) ;
170225
171226 const [ loadOptionsChangeCounter , setCounter ] = useState ( 0 ) ;
172227
@@ -176,8 +231,10 @@ const Select = (props) => {
176231 setCounter ( loadOptionsChangeCounter + 1 ) ;
177232 // eslint-disable-next-line react-hooks/exhaustive-deps
178233 } , [ loadOptionsStr ] ) ;
234+ const isSearchClear = isSearchable || isClearable ;
179235
180- const Component = isMulti && isSearchable ? ClearedMultiSelectFilterable : isMulti ? ClearedMultiSelect : ClearedSelect ;
236+ const Component =
237+ isMulti && isSearchClear ? ClearedMultiSelectFilterable : isMulti ? ClearedMultiSelect : isSearchClear ? ClearedSelectSearchable : ClearedSelect ;
181238
182239 const invalidText = ( ( meta . touched || validateOnMount ) && meta . error ) || '' ;
183240 const text = ( ( meta . touched || validateOnMount ) && meta . warning ) || helperText ;
0 commit comments