From 5dfee6663289cd6bc3016eb16d6166b2e5de481d Mon Sep 17 00:00:00 2001 From: Lucas Correia Date: Fri, 20 May 2016 15:24:06 +0200 Subject: [PATCH] Add showSuggestionsWhenValueIsSet prop, used to control autocomplete filter behaviour when multiple=false --- components/autocomplete/Autocomplete.js | 6 ++++-- components/autocomplete/readme.md | 1 + react-toolbox.d.ts | 5 +++++ spec/components/autocomplete.js | 1 + 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/components/autocomplete/Autocomplete.js b/components/autocomplete/Autocomplete.js index 4c249a31..56678c1f 100644 --- a/components/autocomplete/Autocomplete.js +++ b/components/autocomplete/Autocomplete.js @@ -22,6 +22,7 @@ class Autocomplete extends React.Component { multiple: React.PropTypes.bool, onChange: React.PropTypes.func, selectedPosition: React.PropTypes.oneOf(['above', 'below']), + showSuggestionsWhenValueIsSet: React.PropTypes.bool, source: React.PropTypes.any, value: React.PropTypes.any }; @@ -31,13 +32,14 @@ class Autocomplete extends React.Component { direction: 'auto', selectedPosition: 'above', multiple: true, + showSuggestionsWhenValueIsSet: false, source: {} }; state = { direction: this.props.direction, focus: false, - showAllSuggestions: true, + showAllSuggestions: this.props.showSuggestionsWhenValueIsSet, query: this.query(this.props.value) }; @@ -63,7 +65,7 @@ class Autocomplete extends React.Component { const query = this.query(key); if (this.props.onChange) this.props.onChange(key, event); this.setState( - {focus: false, query, showAllSuggestions: true}, + {focus: false, query, showAllSuggestions: this.props.showSuggestionsWhenValueIsSet}, () => { this.refs.input.blur(); } ); }; diff --git a/components/autocomplete/readme.md b/components/autocomplete/readme.md index 95524c94..64d58637 100644 --- a/components/autocomplete/readme.md +++ b/components/autocomplete/readme.md @@ -50,6 +50,7 @@ class AutocompleteTest extends React.Component { | `onChange` | `Function` | | Callback function that is fired when the components's value changes.| | `source` | `Object` or `Array` | | Object of key/values or array representing all items suggested. | | `selectedPosition` | `String` | `above` | Determines if the selected list is shown above or below input. It can be `above` or `below`. | +| `showSuggestionsWhenValueIsSet` | `Bool` | `false` | If true, the list of suggestions will not be filtered when a value is selected, until the query is modified. | | `value` | `String` or `Array` | | Value or array of values currently selected component.| Additional properties will be passed to the Input Component so you can use `hint`, `name` ... etc. diff --git a/react-toolbox.d.ts b/react-toolbox.d.ts index be6d3e67..8e5e2304 100644 --- a/react-toolbox.d.ts +++ b/react-toolbox.d.ts @@ -171,6 +171,11 @@ declare namespace __RT { * Object of key/values or array representing all items suggested. */ source: Object | Array, + /** + * If true, the list of suggestions will not be filtered when a value is selected, until the query is modified. + * @default false + */ + showSuggestionsWhenValueIsSet?: boolean, /** * Type of the input element. It can be a valid HTML5 input type * @default text diff --git a/spec/components/autocomplete.js b/spec/components/autocomplete.js index a2b11484..ed2bf048 100644 --- a/spec/components/autocomplete.js +++ b/spec/components/autocomplete.js @@ -38,6 +38,7 @@ class AutocompleteTest extends React.Component { onChange={this.handleSimpleChange} source={countriesArray} value={this.state.simple} + showSuggestionsWhenValueIsSet /> );