You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+99-74
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@
4
4
5
5
React Tag Autocomplete is a simple tagging component ready to drop in your React projects. Originally based on the [React Tags project](http://prakhar.me/react-tags/example) by Prakhar Srivastav this version removes the drag-and-drop re-ordering functionality, adds appropriate roles and ARIA states and introduces a resizing text input. [View demo](http://i-like-robots.github.io/react-tags/).
6
6
7
-
**Version 6 of this component is in beta! Please [take a look here](https://github.com/i-like-robots/react-tags/tree/6.0)**✨
7
+
**Please note, this version is in beta, you can check out the [latest stable version here](https://github.com/i-like-robots/react-tags)**📢
8
8
9
9

10
10
@@ -15,7 +15,7 @@ This is a [Node.js] module available through the [npm] registry. Before installi
15
15
Installation is done using the [npm install] command:
The ID attribute given to the listbox element. Default: `ReactTags`.
111
+
105
112
#### tags (optional)
106
113
107
114
An array of selected tags. Each tag is an object which must have an `id` and a `name` property. Defaults to `[]`.
@@ -132,33 +139,29 @@ A callback function to filter suggestion items with. The callback receives two a
132
139
133
140
If no function is supplied the default filter is applied. Defaults to `null`.
134
141
135
-
#### placeholder (optional)
142
+
#### placeholderText (optional)
136
143
137
144
The placeholder string shown for the input. Defaults to `'Add new tag'`.
138
145
139
-
#### ariaLabel (optional)
146
+
#### ariaLabelText (optional)
140
147
141
148
The aria-label string for the input. Defaults to placeholder string.
142
149
143
-
#### noSuggestionsText (optional)
150
+
#### removeButtonText (optional)
144
151
145
-
Message shown if there are no matching suggestions. Defaults to `null`.
152
+
The title text to add to the remove selected tag button. Default `'Click to remove tag'`.
146
153
147
-
#### autofocus (optional)
154
+
#### noSuggestionsText (optional)
148
155
149
-
Boolean parameter to control whether the text-input should be autofocused on mount. Defaults to `true`.
156
+
Message shown if there are no matching suggestions. Defaults to `null`.
150
157
151
158
#### autoresize (optional)
152
159
153
160
Boolean parameter to control whether the text-input should be automatically resized to fit its value. Defaults to `true`.
154
161
155
162
#### delimiters (optional)
156
163
157
-
An array of numbers matching `KeyboardEvent.keyCode` values. When a corresponding key is pressed it will trigger tag selection or creation. Defaults to `[9, 13]` (Tab and return keys).
158
-
159
-
#### delimiterChars (optional)
160
-
161
-
Array of characters matching `KeyboardEvent.key` values. This is useful when needing to support a specific character irrespective of the keyboard layout. Defaults to `[]`.
164
+
Array of keys matching `KeyboardEvent.key` values. When a corresponding key is pressed it will trigger tag selection or creation. Defaults to `['Enter', 'Tab']`.
162
165
163
166
#### minQueryLength (optional)
164
167
@@ -180,42 +183,43 @@ Override the default class names used by the component. Defaults to:
180
183
selectedTag:'react-tags__selected-tag',
181
184
selectedTagName:'react-tags__selected-tag-name',
182
185
search:'react-tags__search',
186
+
searchWrapper:'react-tags__search-wrapper',
183
187
searchInput:'react-tags__search-input',
184
188
suggestions:'react-tags__suggestions',
185
189
suggestionActive:'is-active',
186
190
suggestionDisabled:'is-disabled'
187
191
}
188
192
```
189
193
190
-
#### handleAddition (required)
194
+
#### onAddition (required)
191
195
192
196
Function called when the user wants to add a tag. Receives the tag.
193
197
194
198
```js
195
-
functionhandleAddition(tag) {
199
+
functiononAddition(tag) {
196
200
consttags= [...this.state.tags, tag]
197
201
this.setState({ tags })
198
202
}
199
203
```
200
204
201
-
#### handleDelete (required)
205
+
#### onDelete (required)
202
206
203
207
Function called when the user wants to delete a tag. Receives the tag index.
204
208
205
209
```js
206
-
functionhandleDelete(i) {
210
+
functiononDelete(i) {
207
211
consttags=this.state.tags.slice(0)
208
212
tags.splice(i, 1)
209
213
this.setState({ tags })
210
214
}
211
215
```
212
216
213
-
#### handleInputChange (optional)
217
+
#### onInput (optional)
214
218
215
219
Optional event handler when the input value changes. Receives the current query.
216
220
217
221
```js
218
-
functionhandleInputChange(query) {
222
+
functiononInput(query) {
219
223
if (!this.state.busy) {
220
224
this.setState({ busy:true })
221
225
@@ -226,20 +230,20 @@ function handleInputChange(query) {
226
230
}
227
231
```
228
232
229
-
#### handleFocus (optional)
233
+
#### onFocus (optional)
230
234
231
235
Optional callback function for when the input receives focus. Receives no arguments.
232
236
233
-
#### handleBlur (optional)
237
+
#### onBlur (optional)
234
238
235
239
Optional callback function for when focus on the input is lost. Receives no arguments.
236
240
237
-
#### handleValidate (optional)
241
+
#### onValidate (optional)
238
242
239
243
Optional validation function that determines if tag should be added. Receives the tag object and must return a boolean.
240
244
241
245
```js
242
-
functionhandleValidate(tag) {
246
+
functiononValidate(tag) {
243
247
returntag.name.length>=5;
244
248
}
245
249
```
@@ -256,60 +260,81 @@ Enable users to add new (not suggested) tags. Defaults to `false`.
256
260
257
261
Enable users to delete selected tags when backspace is pressed while focussed on the text input when empty. Defaults to `true`.
258
262
259
-
#### clearInputOnDelete (optional)
263
+
#### tagComponent (optional)
260
264
261
-
Clear the text input when a tag is deleted. Defaults to `true`.
265
+
Provide a custom tag component to render. Receives the tag, button text, and delete callback as props. Defaults to `null`.
An object containing additional attributes that will be applied to the text input. _Please note_ that this prop cannot overwrite existing attributes, it can only add new ones. Defaults to `{}`.
270
294
271
295
296
+
### API
297
+
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()`
309
+
310
+
Clears the input and current query.
311
+
312
+
272
313
### Styling
273
314
274
315
It is possible to customize the appearance of the component, the included styles found in `/example/styles.css` are only an example.
275
316
276
317
277
318
### Development
278
319
279
-
The component is written in ES6 and uses [Webpack](http://webpack.github.io/) as its build tool.
320
+
The component is written in ES6 and uses [Rollup](https://rollupjs.org/) as its build tool. Tests are written with [Jasmine](https://jasmine.github.io/) using [JSDOM](https://github.com/jsdom/jsdom).
280
321
281
-
```
322
+
```sh
282
323
npm install
283
-
npm run dev # open http://localhost:8080
324
+
npm run dev #will open http://localhost:8080 and watch files for changes
284
325
```
285
326
327
+
### Upgrading
286
328
287
-
### Upgrading from 4.x to 5.x
288
-
289
-
1. The `delimiters` option has been removed, any references to this will now be ignored.
To see all changes refer to [the changelog](CHANGELOG.md).
330
+
331
+
#### Upgrading from 5.x to 6.x
314
332
315
-
For smaller changes refer to [the changelog](CHANGELOG.md).
333
+
- React 16.5 or above is now required.
334
+
- Event handlers and callbacks have been renamed to use `on` prefixes, e.g. the `handleAddition()` callback should now be called `onAddition()`.
335
+
- The `delimiters` option is now an array of `KeyboardEvent.key` values and not `KeyboardEvent.keyCode` codes, e.g. `[13, 9]` should now be written as `['Enter', 'Tab']`. See https://keycode.info/ for more information.
336
+
- The `placeholder` option has been renamed `placeholderText`
337
+
- The `ariaLabel` option has been renamed `ariaLabelText`
338
+
- The `delimiterChars` option has been removed, use the `delimiters` option instead.
339
+
- The `clearInputOnDelete` option has been removed and is now the default behaviour
0 commit comments