@@ -23,7 +23,8 @@ import { getHighlightBackgroundColor, shouldHighlightBackground, shouldShowRequi
23
23
import parse from 'autosuggest-highlight/parse' ;
24
24
import match from 'autosuggest-highlight/match' ;
25
25
export var Autocomplete = function ( _a ) {
26
- var _b = _a . customProperties , options = _b . options , registerReturn = _b . registerReturn , fieldId = _a . fieldId , _c = _a . uiSettings , disabled = _c . disabled , description = _c . description , label = _c . label , placeholder = _c . placeholder , size = _c . size , variant = _c . variant , validation = _a . validation ;
26
+ var _b ;
27
+ var _c = _a . customProperties , _d = _c . options , options = _d === void 0 ? [ ] : _d , registerReturn = _c . registerReturn , fieldId = _a . fieldId , _e = _a . uiSettings , disabled = _e . disabled , description = _e . description , label = _e . label , placeholder = _e . placeholder , size = _e . size , variant = _e . variant , validation = _a . validation ;
27
28
var register = useFormContext ( ) . register ;
28
29
if ( register === undefined && registerReturn === undefined ) {
29
30
throw new Error ( 'Either register or registerReturn must be supplied' ) ;
@@ -45,15 +46,17 @@ export var Autocomplete = function (_a) {
45
46
var isRequired = required !== false ;
46
47
var showRequiredLabel = shouldShowRequiredLabel ( isRequired , disabled ) ;
47
48
var highlightBackground = shouldHighlightBackground ( value , isRequired , disabled ) ;
48
- return _jsx ( MUIAutocomplete , { fullWidth : true , size : size , disabled : disabled , id : 'combo-box-demo' , options : options , onChange : handleChange , renderInput : function ( params ) { return _createElement ( TextField , __assign ( { } , params , { error : isErroneous , helperText : isErroneous ? error . message : description , label : label , placeholder : placeholder , InputLabelProps : { required : showRequiredLabel , shrink : true } , onBlur : onBlur , inputRef : ref , variant : variant , key : fieldId , name : fieldId } ) ) ; } , renderOption : function ( props , option , _a ) {
49
+ return _jsx ( MUIAutocomplete , { disabled : disabled , fullWidth : true , id : 'combo-box-demo' , options : options , onBlur : onBlur , onChange : handleChange , renderInput : function ( params ) {
50
+ return _createElement ( TextField , __assign ( { } , params , { error : isErroneous , helperText : isErroneous ? error . message : description , InputLabelProps : { required : showRequiredLabel , shrink : true } , key : fieldId , label : label , name : fieldId , placeholder : placeholder , variant : variant } ) ) ;
51
+ } , renderOption : function ( props , option , _a ) {
49
52
var inputValue = _a . inputValue ;
50
53
var matches = match ( option . label , inputValue ) ;
51
54
var parts = parse ( option . label , matches ) ;
52
55
return ( _jsx ( "li" , __assign ( { } , props , { children : _jsx ( "div" , { children : parts . map ( function ( part , index ) { return ( _jsx ( "span" , __assign ( { style : {
53
56
fontWeight : part . highlight ? 700 : 400 ,
54
57
} } , { children : part . text } ) , index ) ) ; } ) } ) } ) ) ) ;
55
- } , sx : function ( theme ) { return ( {
58
+ } , size : size , sx : function ( theme ) { return ( {
56
59
backgroundColor : getHighlightBackgroundColor ( theme , highlightBackground ) ,
57
- } ) ; } } ) ;
60
+ } ) ; } , value : ( _b = options . find ( function ( option ) { return option . value === value ; } ) ) !== null && _b !== void 0 ? _b : null } ) ;
58
61
} ;
59
62
export default Autocomplete ;
0 commit comments