Skip to content

Commit

Permalink
expose children in AsyncCreatable.js
Browse files Browse the repository at this point in the history
  • Loading branch information
gwyneplaine committed Oct 23, 2017
1 parent a252668 commit b7e876d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
49 changes: 31 additions & 18 deletions src/AsyncCreatable.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import PropTypes from 'prop-types';
import Select from './Select';
import Async from './Async';
import Creatable from './Creatable';
Expand All @@ -21,27 +22,39 @@ class AsyncCreatableSelect extends React.Component {
render () {
return (
<Async {...this.props}>
{(asyncProps) => (
<Creatable {...this.props}>
{(creatableProps) => (
<Select
{...reduce(asyncProps, reduce(creatableProps, {}))}
onInputChange={(input) => {
creatableProps.onInputChange(input);
return asyncProps.onInputChange(input);
}}
ref={(ref) => {
this.select = ref;
creatableProps.ref(ref);
asyncProps.ref(ref);
}}
/>
)}
</Creatable>
)}
{({ ref, ...asyncProps }) => {
const asyncRef = ref;
return (<Creatable {...asyncProps} >
{({ ref, ...creatableProps }) => {
const creatableRef = ref;
return this.props.children({
...creatableProps,
ref: (select) => {
creatableRef(select);
asyncRef(select);
this.select = select;
}
});
}}
</Creatable>);
}}
</Async>
);
}
};

function defaultChildren (props) {
return (
<Select {...props} />
);
};

AsyncCreatableSelect.PropTypes = {
children: PropTypes.func.isRequired, // Child function responsible for creating the inner Select component; (props: Object): PropTypes.element
};

AsyncCreatableSelect.defaultProps = {
children: defaultChildren,
};

export default AsyncCreatableSelect;
2 changes: 1 addition & 1 deletion src/Creatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class CreatableSelect extends React.Component {
this.inputValue = input;

if (onInputChange) {
this.inputValue = onInputChange(input);
this.inputValue = onInputChange(input);
}

return this.inputValue;
Expand Down

0 comments on commit b7e876d

Please sign in to comment.