Skip to content

Commit

Permalink
Fix ignore case logic
Browse files Browse the repository at this point in the history
  • Loading branch information
realplatanopapi committed May 5, 2017
1 parent 9de3d21 commit 4127a91
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 88 deletions.
39 changes: 20 additions & 19 deletions dist/react-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,18 @@ var Async = (function (_Component) {
}
}, {
key: 'loadOptions',
value: function loadOptions(inputValue) {
value: function loadOptions(originalInputValue) {
var _this2 = this;

var loadOptions = this.props.loadOptions;
var _props = this.props;
var ignoreCase = _props.ignoreCase;
var loadOptions = _props.loadOptions;

var cache = this._cache;

// Normalize input to lowercase if ignoreCase prop is true
var inputValue = ignoreCase ? originalInputValue.toLowerCase() : originalInputValue;

if (cache && cache.hasOwnProperty(inputValue)) {
this.setState({
options: cache[inputValue]
Expand Down Expand Up @@ -163,15 +168,15 @@ var Async = (function (_Component) {
});
}

return inputValue;
// Return the original input value
return originalInputValue;
}
}, {
key: '_onInputChange',
value: function _onInputChange(inputValue) {
var _props = this.props;
var ignoreAccents = _props.ignoreAccents;
var ignoreCase = _props.ignoreCase;
var onInputChange = _props.onInputChange;
var _props2 = this.props;
var ignoreAccents = _props2.ignoreAccents;
var onInputChange = _props2.onInputChange;

if (ignoreAccents) {
inputValue = (0, _utilsStripDiacritics2['default'])(inputValue);
Expand All @@ -181,10 +186,6 @@ var Async = (function (_Component) {
onInputChange(inputValue);
}

if (ignoreCase) {
return this.loadOptions(inputValue.toLowerCase());
}

return this.loadOptions(inputValue);
}
}, {
Expand All @@ -198,10 +199,10 @@ var Async = (function (_Component) {
}, {
key: 'noResultsText',
value: function noResultsText() {
var _props2 = this.props;
var loadingPlaceholder = _props2.loadingPlaceholder;
var noResultsText = _props2.noResultsText;
var searchPromptText = _props2.searchPromptText;
var _props3 = this.props;
var loadingPlaceholder = _props3.loadingPlaceholder;
var noResultsText = _props3.noResultsText;
var searchPromptText = _props3.searchPromptText;
var isLoading = this.state.isLoading;

var inputValue = this.inputValue();
Expand All @@ -224,10 +225,10 @@ var Async = (function (_Component) {
value: function render() {
var _this3 = this;

var _props3 = this.props;
var children = _props3.children;
var loadingPlaceholder = _props3.loadingPlaceholder;
var placeholder = _props3.placeholder;
var _props4 = this.props;
var children = _props4.children;
var loadingPlaceholder = _props4.loadingPlaceholder;
var placeholder = _props4.placeholder;
var _state = this.state;
var isLoading = _state.isLoading;
var options = _state.options;
Expand Down
4 changes: 2 additions & 2 deletions dist/react-select.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/dist/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ var Contributors = _react2['default'].createClass({
{ className: 'section-heading' },
this.props.label
),
_react2['default'].createElement(_reactSelect2['default'].Async, { multi: this.state.multi, value: this.state.value, onChange: this.onChange, onValueClick: this.gotoContributor, valueKey: 'github', labelKey: 'name', loadOptions: this.getContributors }),
_react2['default'].createElement(_reactSelect2['default'].Async, { ignoreCase: true, multi: this.state.multi, value: this.state.value, onChange: this.onChange, onValueClick: this.gotoContributor, valueKey: 'github', labelKey: 'name', loadOptions: this.getContributors }),
_react2['default'].createElement(
'div',
{ className: 'checkbox-list' },
Expand Down
39 changes: 20 additions & 19 deletions examples/dist/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,18 @@ var Async = (function (_Component) {
}
}, {
key: 'loadOptions',
value: function loadOptions(inputValue) {
value: function loadOptions(originalInputValue) {
var _this2 = this;

var loadOptions = this.props.loadOptions;
var _props = this.props;
var ignoreCase = _props.ignoreCase;
var loadOptions = _props.loadOptions;

var cache = this._cache;

// Normalize input to lowercase if ignoreCase prop is true
var inputValue = ignoreCase ? originalInputValue.toLowerCase() : originalInputValue;

if (cache && cache.hasOwnProperty(inputValue)) {
this.setState({
options: cache[inputValue]
Expand Down Expand Up @@ -162,15 +167,15 @@ var Async = (function (_Component) {
});
}

return inputValue;
// Return the original input value
return originalInputValue;
}
}, {
key: '_onInputChange',
value: function _onInputChange(inputValue) {
var _props = this.props;
var ignoreAccents = _props.ignoreAccents;
var ignoreCase = _props.ignoreCase;
var onInputChange = _props.onInputChange;
var _props2 = this.props;
var ignoreAccents = _props2.ignoreAccents;
var onInputChange = _props2.onInputChange;

if (ignoreAccents) {
inputValue = (0, _utilsStripDiacritics2['default'])(inputValue);
Expand All @@ -180,10 +185,6 @@ var Async = (function (_Component) {
onInputChange(inputValue);
}

if (ignoreCase) {
return this.loadOptions(inputValue.toLowerCase());
}

return this.loadOptions(inputValue);
}
}, {
Expand All @@ -197,10 +198,10 @@ var Async = (function (_Component) {
}, {
key: 'noResultsText',
value: function noResultsText() {
var _props2 = this.props;
var loadingPlaceholder = _props2.loadingPlaceholder;
var noResultsText = _props2.noResultsText;
var searchPromptText = _props2.searchPromptText;
var _props3 = this.props;
var loadingPlaceholder = _props3.loadingPlaceholder;
var noResultsText = _props3.noResultsText;
var searchPromptText = _props3.searchPromptText;
var isLoading = this.state.isLoading;

var inputValue = this.inputValue();
Expand All @@ -223,10 +224,10 @@ var Async = (function (_Component) {
value: function render() {
var _this3 = this;

var _props3 = this.props;
var children = _props3.children;
var loadingPlaceholder = _props3.loadingPlaceholder;
var placeholder = _props3.placeholder;
var _props4 = this.props;
var children = _props4.children;
var loadingPlaceholder = _props4.loadingPlaceholder;
var placeholder = _props4.placeholder;
var _state = this.state;
var isLoading = _state.isLoading;
var options = _state.options;
Expand Down
39 changes: 20 additions & 19 deletions examples/dist/standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,18 @@ var Async = (function (_Component) {
}
}, {
key: 'loadOptions',
value: function loadOptions(inputValue) {
value: function loadOptions(originalInputValue) {
var _this2 = this;

var loadOptions = this.props.loadOptions;
var _props = this.props;
var ignoreCase = _props.ignoreCase;
var loadOptions = _props.loadOptions;

var cache = this._cache;

// Normalize input to lowercase if ignoreCase prop is true
var inputValue = ignoreCase ? originalInputValue.toLowerCase() : originalInputValue;

if (cache && cache.hasOwnProperty(inputValue)) {
this.setState({
options: cache[inputValue]
Expand Down Expand Up @@ -163,15 +168,15 @@ var Async = (function (_Component) {
});
}

return inputValue;
// Return the original input value
return originalInputValue;
}
}, {
key: '_onInputChange',
value: function _onInputChange(inputValue) {
var _props = this.props;
var ignoreAccents = _props.ignoreAccents;
var ignoreCase = _props.ignoreCase;
var onInputChange = _props.onInputChange;
var _props2 = this.props;
var ignoreAccents = _props2.ignoreAccents;
var onInputChange = _props2.onInputChange;

if (ignoreAccents) {
inputValue = (0, _utilsStripDiacritics2['default'])(inputValue);
Expand All @@ -181,10 +186,6 @@ var Async = (function (_Component) {
onInputChange(inputValue);
}

if (ignoreCase) {
return this.loadOptions(inputValue.toLowerCase());
}

return this.loadOptions(inputValue);
}
}, {
Expand All @@ -198,10 +199,10 @@ var Async = (function (_Component) {
}, {
key: 'noResultsText',
value: function noResultsText() {
var _props2 = this.props;
var loadingPlaceholder = _props2.loadingPlaceholder;
var noResultsText = _props2.noResultsText;
var searchPromptText = _props2.searchPromptText;
var _props3 = this.props;
var loadingPlaceholder = _props3.loadingPlaceholder;
var noResultsText = _props3.noResultsText;
var searchPromptText = _props3.searchPromptText;
var isLoading = this.state.isLoading;

var inputValue = this.inputValue();
Expand All @@ -224,10 +225,10 @@ var Async = (function (_Component) {
value: function render() {
var _this3 = this;

var _props3 = this.props;
var children = _props3.children;
var loadingPlaceholder = _props3.loadingPlaceholder;
var placeholder = _props3.placeholder;
var _props4 = this.props;
var children = _props4.children;
var loadingPlaceholder = _props4.loadingPlaceholder;
var placeholder = _props4.placeholder;
var _state = this.state;
var isLoading = _state.isLoading;
var options = _state.options;
Expand Down
2 changes: 1 addition & 1 deletion examples/src/components/Contributors.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const Contributors = React.createClass({
return (
<div className="section">
<h3 className="section-heading">{this.props.label}</h3>
<Select.Async multi={this.state.multi} value={this.state.value} onChange={this.onChange} onValueClick={this.gotoContributor} valueKey="github" labelKey="name" loadOptions={this.getContributors} />
<Select.Async ignoreCase={true} multi={this.state.multi} value={this.state.value} onChange={this.onChange} onValueClick={this.gotoContributor} valueKey="github" labelKey="name" loadOptions={this.getContributors} />
<div className="checkbox-list">
<label className="checkbox">
<input type="radio" className="checkbox-control" checked={this.state.multi} onChange={this.switchToMulti}/>
Expand Down
39 changes: 20 additions & 19 deletions lib/Async.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,18 @@ var Async = (function (_Component) {
}
}, {
key: 'loadOptions',
value: function loadOptions(inputValue) {
value: function loadOptions(originalInputValue) {
var _this2 = this;

var loadOptions = this.props.loadOptions;
var _props = this.props;
var ignoreCase = _props.ignoreCase;
var loadOptions = _props.loadOptions;

var cache = this._cache;

// Normalize input to lowercase if ignoreCase prop is true
var inputValue = ignoreCase ? originalInputValue.toLowerCase() : originalInputValue;

if (cache && cache.hasOwnProperty(inputValue)) {
this.setState({
options: cache[inputValue]
Expand Down Expand Up @@ -161,15 +166,15 @@ var Async = (function (_Component) {
});
}

return inputValue;
// Return the original input value
return originalInputValue;
}
}, {
key: '_onInputChange',
value: function _onInputChange(inputValue) {
var _props = this.props;
var ignoreAccents = _props.ignoreAccents;
var ignoreCase = _props.ignoreCase;
var onInputChange = _props.onInputChange;
var _props2 = this.props;
var ignoreAccents = _props2.ignoreAccents;
var onInputChange = _props2.onInputChange;

if (ignoreAccents) {
inputValue = (0, _utilsStripDiacritics2['default'])(inputValue);
Expand All @@ -179,10 +184,6 @@ var Async = (function (_Component) {
onInputChange(inputValue);
}

if (ignoreCase) {
return this.loadOptions(inputValue.toLowerCase());
}

return this.loadOptions(inputValue);
}
}, {
Expand All @@ -196,10 +197,10 @@ var Async = (function (_Component) {
}, {
key: 'noResultsText',
value: function noResultsText() {
var _props2 = this.props;
var loadingPlaceholder = _props2.loadingPlaceholder;
var noResultsText = _props2.noResultsText;
var searchPromptText = _props2.searchPromptText;
var _props3 = this.props;
var loadingPlaceholder = _props3.loadingPlaceholder;
var noResultsText = _props3.noResultsText;
var searchPromptText = _props3.searchPromptText;
var isLoading = this.state.isLoading;

var inputValue = this.inputValue();
Expand All @@ -222,10 +223,10 @@ var Async = (function (_Component) {
value: function render() {
var _this3 = this;

var _props3 = this.props;
var children = _props3.children;
var loadingPlaceholder = _props3.loadingPlaceholder;
var placeholder = _props3.placeholder;
var _props4 = this.props;
var children = _props4.children;
var loadingPlaceholder = _props4.loadingPlaceholder;
var placeholder = _props4.placeholder;
var _state = this.state;
var isLoading = _state.isLoading;
var options = _state.options;
Expand Down
16 changes: 8 additions & 8 deletions src/Async.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,13 @@ export default class Async extends Component {
this.setState({ options: [] });
}

loadOptions (inputValue) {
const { loadOptions } = this.props;
loadOptions (originalInputValue) {
const { ignoreCase, loadOptions } = this.props;
const cache = this._cache;

// Normalize input to lowercase if ignoreCase prop is true
const inputValue = ignoreCase ? originalInputValue.toLowerCase() : originalInputValue;

if (
cache &&
cache.hasOwnProperty(inputValue)
Expand Down Expand Up @@ -134,11 +137,12 @@ export default class Async extends Component {
});
}

return inputValue;
// Return the original input value
return originalInputValue;
}

_onInputChange (inputValue) {
const { ignoreAccents, ignoreCase, onInputChange } = this.props;
const { ignoreAccents, onInputChange } = this.props;

if (ignoreAccents) {
inputValue = stripDiacritics(inputValue);
Expand All @@ -149,10 +153,6 @@ export default class Async extends Component {
onInputChange(inputValue);
}

if (ignoreCase) {
return this.loadOptions(inputValue.toLowerCase());
}

return this.loadOptions(inputValue);
}

Expand Down

0 comments on commit 4127a91

Please sign in to comment.