@@ -47,6 +47,8 @@ class App extends React.Component {
47
47
{ id: 6 , name: " Apricots" }
48
48
]
49
49
}
50
+
51
+ this .reactTags = React .createRef ()
50
52
}
51
53
52
54
onDelete (i ) {
@@ -63,6 +65,7 @@ class App extends React.Component {
63
65
render () {
64
66
return (
65
67
< ReactTags
68
+ ref= {this .reactTags }
66
69
tags= {this .state .tags }
67
70
suggestions= {this .state .suggestions }
68
71
onDelete= {this .onDelete .bind (this )}
@@ -259,11 +262,31 @@ Enable users to delete selected tags when backspace is pressed while focussed on
259
262
260
263
#### tagComponent (optional)
261
264
262
- Provide a custom tag component to render. Defaults to ` null ` .
265
+ Provide a custom tag component to render. Receives the tag, button text, and delete callback as props. Defaults to ` null ` .
266
+
267
+ ``` jsx
268
+ function TagComponent ({ tag, removeButtonText, onDelete }) {
269
+ return (
270
+ < button type= ' button' title= {removeButtonText} onClick= {onDelete}>
271
+ {tag .name }
272
+ < / button>
273
+ )
274
+ }
275
+ ```
263
276
264
277
#### suggestionComponent (optional)
265
278
266
- Provide a custom suggestion component to render. Default: ` null ` .
279
+ Provide a custom suggestion component to render. Receives the suggestion and current query as props. Defaults to ` null ` .
280
+
281
+ ``` jsx
282
+ function SuggestionComponent ({ item, query }) {
283
+ return (
284
+ < span id= {item .id } className= {item .name === query ? ' match' : ' no-match' }>
285
+ {item .name }
286
+ < / span>
287
+ )
288
+ }
289
+ ```
267
290
268
291
#### inputAttributes (optional)
269
292
@@ -272,11 +295,20 @@ An object containing additional attributes that will be applied to the text inpu
272
295
273
296
### API
274
297
275
- #### addTag(tag)
298
+ By adding a ` ref ` to any instances of this component you can access its API methods.
299
+
300
+ #### ` addTag(tag) `
301
+
302
+ Adds a tag to the list of selected tags. This will trigger the validation and addition callbacks.
303
+
304
+ #### ` deleteTag(index) `
305
+
306
+ Removes a tag from the list of selected tags. This will trigger the delete callback.
307
+
308
+ #### ` clearInput() `
276
309
277
- #### deleteTag(index)
310
+ Clears the input and current query.
278
311
279
- #### clearInput()
280
312
281
313
### Styling
282
314
0 commit comments