Skip to content

Commit c2346f6

Browse files
committedJan 31, 2019
Allow passing a custom base select component. This behaviour can be helpful if you have your own custom wrapper for the react-select component.
1 parent 5913fea commit c2346f6

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed
 

‎.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ node_modules
33
*.log
44
lib
55
es
6+
.idea/
7+
8+
# Repository is using Yarn
9+
package-lock.json

‎src/__tests__/async-paginate-test.jsx

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { Component } from 'react';
22
import { shallow, mount } from 'enzyme';
33
import { SelectBase } from 'react-select';
44

@@ -717,3 +717,23 @@ describe('loadOptions', () => {
717717
expect(reduceOptions.mock.calls[0][2]).toBe(additionalNext);
718718
});
719719
});
720+
721+
test('should allow to puss custom Select component', () => {
722+
// eslint-disable-next-line react/prefer-stateless-function
723+
class MyCustomSelectWrapper extends Component {
724+
render() {
725+
return <SelectBase {...this.props} />;
726+
}
727+
}
728+
729+
const wrapper = mount(
730+
<AsyncPaginate
731+
SelectComponent={MyCustomSelectWrapper}
732+
loadOptions={() => {
733+
}}
734+
/>,
735+
);
736+
737+
expect(wrapper.find(MyCustomSelectWrapper))
738+
.toBeTruthy();
739+
});

‎src/async-paginate.jsx

+13-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ const sleep = (ms) => new Promise((resolve) => {
1616
}, ms);
1717
});
1818

19+
// Supports forwardRef https://github.com/facebook/prop-types/issues/200
20+
const ComponentPropType = PropTypes.oneOfType([
21+
PropTypes.func,
22+
PropTypes.string,
23+
PropTypes.shape({ render: PropTypes.func.isRequired }),
24+
]);
25+
1926
class AsyncPaginate extends Component {
2027
static propTypes = {
2128
loadOptions: PropTypes.func.isRequired,
@@ -27,6 +34,7 @@ class AsyncPaginate extends Component {
2734
additional: PropTypes.any,
2835
reduceOptions: PropTypes.func,
2936

37+
SelectComponent: ComponentPropType,
3038
components: PropTypes.objectOf(PropTypes.func),
3139

3240
// eslint-disable-next-line react/forbid-prop-types
@@ -43,6 +51,7 @@ class AsyncPaginate extends Component {
4351
additional: null,
4452
reduceOptions: defaultReduceOptions,
4553

54+
SelectComponent: SelectBase,
4655
components: {},
4756

4857
cacheUniq: null,
@@ -245,6 +254,8 @@ class AsyncPaginate extends Component {
245254
const {
246255
selectRef,
247256
components,
257+
SelectComponent,
258+
...props
248259
} = this.props;
249260

250261
const {
@@ -256,8 +267,8 @@ class AsyncPaginate extends Component {
256267
const currentOptions = optionsCache[search] || this.getInitialCache();
257268

258269
return (
259-
<SelectBase
260-
{...this.props}
270+
<SelectComponent
271+
{...props}
261272
inputValue={search}
262273
menuIsOpen={menuIsOpen}
263274
onMenuClose={this.onMenuClose}

0 commit comments

Comments
 (0)
Please sign in to comment.