Skip to content

Commit 360728a

Browse files
committed
Merge branch 'master' into 6.0
2 parents f4df932 + d2c569c commit 360728a

File tree

7 files changed

+40
-12
lines changed

7 files changed

+40
-12
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@
2020
- Removed `delimiterChars` option
2121
- Updated React dependency to 16.5+
2222

23+
## 5.12.1
24+
25+
- Fixed an issue where the `componentDidUpdate()` callback of the input component can be called too many times
26+
27+
## 5.12.0
28+
29+
- Added `noSuggestionsText` option ([jraack](https://github.com/jraack))
30+
2331
## 5.11.2
2432

2533
- Fixed an issue with the delimiter key logic which would attempt to add a previously selected suggestion even when it was no longer in the suggestion list.

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Build status](https://api.travis-ci.org/i-like-robots/react-tags.svg?branch=master)](https://travis-ci.org/i-like-robots/react-tags) [![Coverage Status](https://coveralls.io/repos/github/i-like-robots/react-tags/badge.svg?branch=master)](https://coveralls.io/github/i-like-robots/react-tags)
44

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.
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/).
66

77
**Please note, this version is in beta, you can check out the [latest stable version here](https://github.com/i-like-robots/react-tags)** 📢
88

@@ -83,6 +83,7 @@ ReactDOM.render(<App />, document.getElementById('app'))
8383
- [`suggestionsFilter`](#suggestionsfilter-optional)
8484
- [`placeholderText`](#placeholdertext-optional)
8585
- [`removeButtonText`](#removeButtontext-optional)
86+
- [`noSuggestionsText`](#noSuggestionsText-optional)
8687
- [`autoresize`](#autoresize-optional)
8788
- [`delimiters`](#delimiters-optional)
8889
- [`minQueryLength`](#minquerylength-optional)
@@ -142,6 +143,10 @@ The placeholder string shown for the input. Defaults to `'Add new tag'`.
142143

143144
The title text to add to the remove selected tag button. Default `'Click to remove tag'`.
144145

146+
#### noSuggestionsText (optional)
147+
148+
Message shown if there are no matching suggestions. Defaults to `null`.
149+
145150
#### autoresize (optional)
146151

147152
Boolean parameter to control whether the text-input should be automatically resized to fit its value. Defaults to `true`.

example/main.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
2-
import ReactDom from 'react-dom'
3-
import Tags from '../lib/ReactTags'
2+
import ReactDOM from 'react-dom'
3+
import ReactTags from '../lib/ReactTags'
44
import suggestions from './countries'
55

66
class App extends React.Component {
@@ -31,7 +31,7 @@ class App extends React.Component {
3131
return (
3232
<React.Fragment>
3333
<p>Select the countries you have visited using React Tags below:</p>
34-
<Tags
34+
<ReactTags
3535
tags={this.state.tags}
3636
suggestions={this.state.suggestions}
3737
onDelete={this.onDelete.bind(this)}
@@ -43,4 +43,4 @@ class App extends React.Component {
4343
}
4444
}
4545

46-
ReactDom.render(<App />, document.getElementById('app'))
46+
ReactDOM.render(<App />, document.getElementById('app'))

lib/Input.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ const STYLE_PROPS = [
1414
'fontFamily',
1515
'fontWeight',
1616
'fontStyle',
17-
'letterSpacing'
17+
'letterSpacing',
18+
'textTransform'
1819
]
1920

2021
class Input extends React.Component {
@@ -33,8 +34,10 @@ class Input extends React.Component {
3334
}
3435
}
3536

36-
componentDidUpdate () {
37-
this.updateInputWidth()
37+
componentDidUpdate ({ query, placeholder }) {
38+
if (query !== this.props.query || placeholder !== this.props.placeholder) {
39+
this.updateInputWidth()
40+
}
3841
}
3942

4043
copyInputStyles () {

lib/ReactTags.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,13 @@ function defaultSuggestionsFilter (item, query) {
7575
}
7676

7777
function getOptions (query) {
78-
const filtered = this.props.suggestions.filter((item) => this.props.suggestionsFilter(item, query))
79-
return filtered.slice(0, this.props.maxSuggestionsLength)
78+
const options = this.props.suggestions.filter((item) => this.props.suggestionsFilter(item, query))
79+
80+
if (options.length === 0 && this.props.noSuggestionsText) {
81+
options.push({ id: 0, name: this.props.noSuggestionsText, disabled: true, disableMarkIt: true })
82+
}
83+
84+
return options.slice(0, this.props.maxSuggestionsLength)
8085
}
8186

8287
class ReactTags extends React.Component {
@@ -256,6 +261,7 @@ ReactTags.defaultProps = {
256261
tags: [],
257262
placeholderText: 'Add new tag',
258263
removeButtonText: 'Click to remove tag',
264+
noSuggestionsText: null,
259265
suggestions: [],
260266
suggestionsFilter: defaultSuggestionsFilter,
261267
autoresize: true,
@@ -276,6 +282,7 @@ ReactTags.propTypes = {
276282
tags: PropTypes.arrayOf(PropTypes.object),
277283
placeholderText: PropTypes.string,
278284
removeButtonText: PropTypes.string,
285+
noSuggestionsText: PropTypes.string,
279286
suggestions: PropTypes.arrayOf(PropTypes.object),
280287
suggestionsFilter: PropTypes.func,
281288
autoresize: PropTypes.bool,

lib/Suggestions.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ class Suggestions extends React.Component {
4444
className={classNames.join(' ')}
4545
aria-disabled={item.disabled === true}
4646
onMouseDown={this.onMouseDown.bind(this, item)}>
47-
<SuggestionComponent item={item} query={this.props.query} />
47+
{item.disableMarkIt ? item.name
48+
: <SuggestionComponent item={item} query={this.props.query} />}
4849
</li>
4950
)
5051
})

spec/ReactTags.spec.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,13 @@ describe('React Tags', () => {
228228
it('shows the suggestions list when there are suggestions available', () => {
229229
type(query)
230230
expect($('ul[role="listbox"]')).toBeTruthy()
231+
})
232+
233+
it('shows a message when there are no suggestions available', () => {
234+
createInstance({ noSuggestionsText: 'No suggestions found' })
231235

232236
type('xyz')
233-
expect($('ul[role="listbox"]')).toBeNull()
237+
expect($('ul[role="listbox"] > li:first-child').textContent).toEqual('No suggestions found')
234238
})
235239

236240
it('hides the suggestions list when the input is not focused', () => {

0 commit comments

Comments
 (0)