Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ For multi-select inputs, when providing a custom `filterOptions` method, remembe
clearable | bool | should it be possible to reset value
clearAllText | string | title for the "clear" control when multi: true
clearValueText | string | title for the "clear" control
delayAsyncMs | number | time delay before querying after an input change
delimiter | string | delimiter to use to join multiple values
disableCache | bool | disables the options cache for asyncOptions
disabled | bool | whether the Select is disabled or not
Expand Down
36 changes: 29 additions & 7 deletions src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var Select = React.createClass({
clearAllText: React.PropTypes.string, // title for the "clear" control when multi: true
clearValueText: React.PropTypes.string, // title for the "clear" control
clearable: React.PropTypes.bool, // should it be possible to reset value
delayAsyncMs: React.PropTypes.number, // time delay before querying after an input change
delimiter: React.PropTypes.string, // delimiter to use to join multiple values
disabled: React.PropTypes.bool, // whether the Select is disabled or not
filterOption: React.PropTypes.func, // method to filter a single option: function(option, filterString)
Expand Down Expand Up @@ -68,6 +69,7 @@ var Select = React.createClass({
clearAllText: 'Clear all',
clearValueText: 'Clear value',
clearable: true,
delayAsyncMs: 0,
delimiter: ',',
disabled: false,
ignoreCase: true,
Expand Down Expand Up @@ -103,6 +105,7 @@ var Select = React.createClass({
* - placeholder
* - focusedOption
*/
inputTimer: undefined,
isFocused: false,
isLoading: false,
isOpen: false,
Expand Down Expand Up @@ -494,23 +497,42 @@ var Select = React.createClass({
this._optionsFilterString = event.target.value;

if (this.props.onInputChange) {
this.props.onInputChange(event.target.value);
this.props.onInputChange(this._optionsFilterString);
}

if (this.props.asyncOptions) {
var callAsyncLoad = function() {
this.loadAsyncOptions(this._optionsFilterString, {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick note that this._optionsFilterString is preferable to event.target.value, since in the case of this function it doesn't require the argument to be redefined in its closure.

isLoading: false,
isOpen: true
}, this._bindCloseMenuIfClickedOutside);
}.bind(this);

if (this.props.delayAsyncMs) {
if (this.state.inputTimer) {
clearTimeout(this.state.inputTimer);
}

var wait = setTimeout(function() {
callAsyncLoad();
}, this.props.delayAsyncMs);

this.setState({
inputTimer: wait
});
} else {
callAsyncLoad();
}

this.setState({
isLoading: true,
inputValue: event.target.value
inputValue: this._optionsFilterString
});
this.loadAsyncOptions(event.target.value, {
isLoading: false,
isOpen: true
}, this._bindCloseMenuIfClickedOutside);
} else {
var filteredOptions = this.filterOptions(this.state.options);
this.setState({
isOpen: true,
inputValue: event.target.value,
inputValue: this._optionsFilterString,
filteredOptions: filteredOptions,
focusedOption: this._getNewFocusedOption(filteredOptions)
}, this._bindCloseMenuIfClickedOutside);
Expand Down