Skip to content

Commit 0bce911

Browse files
committed
Fixes Autocomplete error when provided value prop that is not in source option while preserving value text
1 parent a825208 commit 0bce911

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

components/autocomplete/Autocomplete.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,13 @@ const factory = (Chip, Input) => {
154154
}
155155

156156
query (key) {
157-
return !this.props.multiple && key ? this.source().get(key) : '';
158-
}
157+
var query_value = '';
158+
if(!this.props.multiple && key) {
159+
var source_value = this.source().get(key)
160+
query_value = source_value ? source_value : key;
161+
}
162+
return query_value;
163+
}
159164

160165
suggestions () {
161166
let suggest = new Map();

lib/autocomplete/Autocomplete.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,13 @@ var factory = function factory(Chip, Input) {
165165
}, {
166166
key: 'query',
167167
value: function query(key) {
168-
return !this.props.multiple && key ? this.source().get(key) : '';
168+
var query_value = '';
169+
if(!this.props.multiple && key) {
170+
var source_value = this.source().get(key)
171+
query_value = source_value ? source_value : key;
169172
}
173+
return query_value;
174+
}
170175
}, {
171176
key: 'suggestions',
172177
value: function suggestions() {
@@ -474,4 +479,4 @@ var factory = function factory(Chip, Input) {
474479
var Autocomplete = factory(_Chip2.default, _Input2.default);
475480
exports.default = (0, _reactCssThemr.themr)(_identifiers.AUTOCOMPLETE)(Autocomplete);
476481
exports.autocompleteFactory = factory;
477-
exports.Autocomplete = Autocomplete;
482+
exports.Autocomplete = Autocomplete;

0 commit comments

Comments
 (0)