Skip to content

Commit

Permalink
ds/ns - allow ReactSelect.AsyncCreatable
Browse files Browse the repository at this point in the history
If you pass in loadOptions as well as creatable,
we will now render an AsyncCreatable.
  • Loading branch information
natalieschauser authored and Dilraj Singh committed Apr 17, 2018
1 parent 18d2a09 commit 5533e0d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/components/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,14 @@ class Select extends React.Component {
render() {
const { className, multi, value, valueComponent, ...props } = this.props;
delete props.onChange; // don't pass onChange prop to react-select
const SelectElement = this.props.loadOptions ? ReactSelect.Async :
this.props.creatable ? ReactSelect.Creatable :
ReactSelect;
let SelectElement = ReactSelect;
if (this.props.loadOptions && this.props.creatable) {
SelectElement = ReactSelect.AsyncCreatable;
} else if (this.props.loadOptions) {
SelectElement = ReactSelect.Async;
} else if (this.props.creatable) {
SelectElement = ReactSelect.Creatable;
}
const classNames = classnames(className, { 'select-async': this.props.loadOptions });
const valueComponentRenderer = valueComponent ? valueComponent :
multi ? SelectMultiValue :
Expand Down
12 changes: 12 additions & 0 deletions test/components/Select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,16 @@ describe('<Select />', () => {
component.focus();
sinon.assert.calledOnce(component.selectEl.focus);
});

it('should render AsyncCreatable if loadOptions and creatable', () => {
const getOptions = () => {};

const component = shallow(<Select loadOptions={getOptions} creatable />);
assert.equal(component.type(), ReactSelect.AsyncCreatable);
});

it('should render Creatable if creatable', () => {
const component = shallow(<Select creatable />);
assert.equal(component.type(), ReactSelect.Creatable);
});
});

0 comments on commit 5533e0d

Please sign in to comment.