File tree Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -133,6 +133,7 @@ Change valueExtractor and pass the data to Autocomplete without fetchDataUrl
133133 autoCorrect | Disable auto-correct | Boolean | true
134134 highlightText | Highlight search results | Boolean | true
135135 rightContent | Render additional text to the right of the item | Boolean | false
136+ resetOnSelect | Reset the input after choosing an item | Boolean | false
136137 minimumCharactersCount | Perform API request after certain number of characters entered | Number | 2
137138 waitInterval | Timeout between user finished typing and new data fetch | Number | 400
138139 placeholder | Autocomplete input placeholder text | String | Add Item
Original file line number Diff line number Diff line change @@ -100,11 +100,15 @@ class Autocomplete extends Component {
100100 }
101101
102102 setItem ( value ) {
103- const { index, handleSelectItem, valueExtractor} = this . props ;
104- const capitalizedValue = capitalizeFirstLetter ( valueExtractor ( value ) ) ;
105- this . setState ( { inputValue : capitalizedValue } ) ;
106-
103+ const { index, handleSelectItem, valueExtractor, resetOnSelect } = this . props ;
107104 handleSelectItem ( value , index ) ;
105+
106+ if ( resetOnSelect ) {
107+ this . setState ( { inputValue : '' } ) ;
108+ } else {
109+ const capitalizedValue = capitalizeFirstLetter ( valueExtractor ( value ) ) ;
110+ this . setState ( { inputValue : capitalizedValue } ) ;
111+ }
108112 }
109113
110114 componentDidMount ( ) {
@@ -195,6 +199,7 @@ Autocomplete.defaultProps = {
195199 minimumCharactersCount : 2 ,
196200 highlightText : true ,
197201 waitInterval : WAIT_INTERVAL ,
202+ resetOnSelect : false ,
198203} ;
199204
200205Autocomplete . propTypes = {
@@ -208,6 +213,7 @@ Autocomplete.propTypes = {
208213 highlightText : bool ,
209214 rightContent : bool ,
210215 autoCorrect : bool ,
216+ resetOnSelect : bool ,
211217
212218 valueExtractor : func ,
213219 renderIcon : func ,
You can’t perform that action at this time.
0 commit comments