Skip to content

Commit

Permalink
feat: support AsyncCreatable as well
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip committed Jan 30, 2019
1 parent 24bdbb4 commit 26c06f0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import { ReactEventHandler } from 'react';
import ReactSelect from 'react-select';
import ReactAsyncSelect, { Props as AsyncProps } from 'react-select/lib/Async'; // we can live with it, as it adds very little overhead (just a wrapper around Select)
import ReactAsyncCreatableSelect from 'react-select/lib/AsyncCreatable';
import ReactCreatableSelect, { Props as CreatableProps } from 'react-select/lib/Creatable';
import { Props } from 'react-select/lib/Select';

Expand Down Expand Up @@ -46,7 +47,9 @@ export interface ISelectCreatableProps
extends ISelectBaseProps,
Omit<CreatableProps<ISelectOption>, 'noOptionsMessage' | 'loadingMessage'> {}

export type ISelect = ISelectProps | ISelectAsyncProps | ISelectCreatableProps;
export type ISelectAsyncCreatableProps = ISelectCreatableProps & ISelectAsyncProps;

export type ISelect = ISelectProps | ISelectAsyncProps | ISelectCreatableProps | ISelectAsyncCreatableProps;

export interface ISelectOption {
label: string;
Expand Down Expand Up @@ -102,6 +105,10 @@ export const Select: React.FunctionComponent<ISelect> = props => {
styles: customStyles(),
};

if ('loadOptions' in props && 'onCreateOption' in props) {
return <ReactAsyncCreatableSelect {...actualProps} />;
}

if ('loadOptions' in props) {
return <ReactAsyncSelect {...actualProps} />;
}
Expand Down

0 comments on commit 26c06f0

Please sign in to comment.