Skip to content
Open
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "react-select",
"name": "react-select-rgee",
"version": "1.0.0-rc.10",
"description": "A Select control built with and for ReactJS",
"main": "lib/index.js",
Expand Down
26 changes: 23 additions & 3 deletions src/Async.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const propTypes = {
onChange: PropTypes.func, // onChange handler: function (newValue) {}
onInputChange: PropTypes.func, // optional for keeping track of what is being typed
options: PropTypes.array.isRequired, // array of options
pagination: PropTypes.bool, // automatically load more options when the option list is scrolled to the end; default to false
pagination: PropTypes.bool, // automatically load more options when the option list is scrolled to the end; default to false
placeholder: PropTypes.oneOfType([ // field placeholder, displayed when there's no value (shared with Select)
PropTypes.string,
PropTypes.node
Expand Down Expand Up @@ -63,6 +63,7 @@ export default class Async extends Component {

this.onInputChange = this.onInputChange.bind(this);
this.onMenuScrollToBottom = this.onMenuScrollToBottom.bind(this);
this.onChange = this.onChange.bind(this);
}

componentDidMount () {
Expand Down Expand Up @@ -104,6 +105,10 @@ export default class Async extends Component {
!pagination ||
(pagination && (cache[inputValue].page >= page || cache[inputValue].hasReachedLastPage))
) {
this.setState({
isLoading: false,
isLoadingPage: false
});
return;
}
}
Expand Down Expand Up @@ -178,8 +183,11 @@ export default class Async extends Component {
onInputChange(transformedInputValue);
}

let oldInputValue = this.state.inputValue;
Copy link
Owner

Choose a reason for hiding this comment

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

setting state is async. This with the check two lines below will lead to bugs where the loadOptions is not called when it should have been.

this.setState({ inputValue });
this.loadOptions(transformedInputValue);
if (inputValue !== oldInputValue) {
this.loadOptions(transformedInputValue);
}

// Return the original input value to avoid modifying the user's view of the input while typing.
return inputValue;
Expand Down Expand Up @@ -208,8 +216,19 @@ export default class Async extends Component {
this.loadOptions(inputValue, this.state.page + 1);
}

onChange(value) {
this.props.onChange(value);

if (this.props.pagination) {
let remainingOptions = this.state.options.length - value.length;
Copy link
Owner

@TheSharpieOne TheSharpieOne Jan 2, 2018

Choose a reason for hiding this comment

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

What is value here? It can be a string or an object as well as an array. When it is not an array, this line doesn't make much sense.

Copy link
Author

Choose a reason for hiding this comment

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

ah, you're correct. these fixes were specifically for my use case which was multi-select async pagination. let me test out some of the other edge cases and get back to you with another commit.

if (remainingOptions < 4) {
this.onMenuScrollToBottom(this.state.inputValue);
}
}
}

render () {
const { children, loadingPlaceholder, multi, onChange, placeholder, value } = this.props;
const { children, loadingPlaceholder, multi, placeholder, value } = this.props;
const { isLoading, isLoadingPage, options } = this.state;

const props = {
Expand All @@ -225,6 +244,7 @@ export default class Async extends Component {
isLoading,
onInputChange: this.onInputChange,
onMenuScrollToBottom: this.onMenuScrollToBottom,
onChange: this.onChange
});
}
}
Expand Down