Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added shouldReloadOptions option to Async component #1480

Closed
wants to merge 2 commits into from
Closed
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
19 changes: 18 additions & 1 deletion src/Async.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const propTypes = {
React.PropTypes.node
]),
loadOptions: React.PropTypes.func.isRequired, // callback to load options asynchronously; (inputValue: string, callback: Function): ?Promise
shouldReloadOptions: React.PropTypes.func, // function to check if we should reload the loptions; (): bool
multi: React.PropTypes.bool, // multi-value input
options: PropTypes.array.isRequired, // array of options
placeholder: React.PropTypes.oneOfType([ // field placeholder, displayed when there's no value (shared with Select)
Expand Down Expand Up @@ -67,6 +68,12 @@ export default class Async extends Component {
}
}

componentWillReceiveProps (props) {
if (props.shouldReloadOptions && props.shouldReloadOptions()) {
this.loadOptions();
}
}

componentWillUpdate (nextProps, nextState) {
const propertiesToSync = ['options'];
propertiesToSync.forEach((prop) => {
Expand Down Expand Up @@ -155,6 +162,15 @@ export default class Async extends Component {
return this.loadOptions(inputValue);
}

onOpen () {
if (this.props.shouldReloadOptions && this.props.shouldReloadOptions()) {
this.loadOptions();
}
if (this.props.onOpen) {
this.props.onOpen();
}
}

inputValue() {
if (this.select) {
return this.select.state.inputValue;
Expand Down Expand Up @@ -202,7 +218,8 @@ export default class Async extends Component {
...this.props,
...props,
isLoading,
onInputChange: this._onInputChange
onInputChange: this._onInputChange,
onOpen: this.onOpen.bind(this)
});
}
}
Expand Down