@@ -6,14 +6,40 @@ const Autosuggest = require('react-autosuggest');
6
6
/******************************************************************************/
7
7
/*/
8
8
9
+ AutoComplete is the text input field for entering node labels to:
10
+ * search for nodes,
11
+ * edit existing nodes,
12
+ * and add new nodes.
13
+
14
+ Main features:
15
+
16
+ * It interactively provides a list of suggestions that match the current
17
+ input, e.g. typing "ah" will display a list of suggestions including "Ah
18
+ Long", "Ah Seung", and "Oahu Railroad Station".
19
+
20
+ * Users can highlight suggestions (via mouseover or with keyboard arrows)
21
+
22
+ * Users can select a suggestion (via clicking or hitting return)
23
+
24
+ AutoComplete is a wrapper class for the open source AutoSuggest component,
25
+ which handles the actual rendering of the suggestions list. AutoComplete
26
+ provides an interface to NodeSelector and EdgeEntry. AutoComplete also
27
+ provides the handler routines for generating the suggestions list and
28
+ handling highlights and selections.
29
+
30
+
31
+
9
32
This relies on the react-autosuggest component.
10
33
See documentation: https://github.com/moroshko/react-autosuggest
11
34
12
35
13
36
To Use:
14
37
<AutoComplete
38
+
15
39
data={this.state.data}
40
+ value={label}
16
41
disableSuggestions={this.state.canEdit}
42
+
17
43
onInputChange={this.handleInputChange}
18
44
onSelection={this.handleNodeSelection}
19
45
onHighlight={this.handleSuggestionHighlight}
@@ -26,8 +52,8 @@ const Autosuggest = require('react-autosuggest');
26
52
data is mapped to this.props.data
27
53
This is how graph data is passed to the AutoComplete component.
28
54
29
- requestClearValue is mapped to this.props.clearValue
30
- Parent component can call this to clear the input field .
55
+ value is mapped to this.props.setValue
56
+ Use this to set the autocomplete value externally .
31
57
32
58
disableSuggesions is mapped to this.props.disabled
33
59
Set to true to stop making suggestions
@@ -171,7 +197,7 @@ class AutoComplete extends React.Component {
171
197
onSuggestionSelected ( event , { suggestion } ) {
172
198
// call parent handler
173
199
if ( suggestion . isAddNew ) {
174
- console . log ( 'Add new:' , this . state . value , 'suggestion' , suggestion ) ;
200
+ // console.log('Add new:', this.state.value, 'suggestion',suggestion);
175
201
this . props . onSelection ( this . state . value )
176
202
} else {
177
203
this . props . onSelection ( suggestion )
@@ -186,13 +212,17 @@ class AutoComplete extends React.Component {
186
212
return this . props . disableSuggestions
187
213
}
188
214
215
+ setValue ( value ) {
216
+ // console.log('...AutoComplete.setValue to',value)
217
+ this . setState ( { value : value } )
218
+ }
189
219
clearValue ( ) {
190
220
this . setState ( { value :'' } )
191
221
}
192
222
193
223
componentWillReceiveProps ( nextProps ) {
194
224
// console.log('AutoComplete: componentWillReceiveProps',nextProps)
195
- if ( nextProps . requestClearValue ) this . clearValue ( )
225
+ if ( nextProps . value !== undefined ) this . setValue ( nextProps . value )
196
226
}
197
227
198
228
render ( ) {
0 commit comments