Skip to content

Commit 87a82b3

Browse files
authored
Bugfix/remove circular refs (JedWatson#1855)
* Fix issue with Circular references. Because Select was used in Async, AsyncCreatable, and Creatable and those components were ref in Select, there was a circular dependency. It seems mostackage managers handled this ok, but this may cause an issue with hoisting (e.g. rollup and webpack 3).# Please enter the commit message for your changes. Lines starting * Add focus test back in to Async * Make components static fields on Select instance
1 parent 9acb454 commit 87a82b3

9 files changed

Lines changed: 32 additions & 23 deletions

File tree

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var initGulpTasks = require('react-component-gulp-tasks');
44
var taskConfig = {
55

66
component: {
7-
name: 'Select',
7+
name: 'index',
88
dependencies: [
99
'classnames',
1010
'react-input-autosize',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "react-select",
33
"version": "1.0.0-rc.5",
44
"description": "A Select control built with and for ReactJS",
5-
"main": "lib/Select.js",
5+
"main": "lib/index.js",
66
"style": "dist/react-select.min.css",
77
"author": "Jed Watson",
88
"license": "MIT",

src/AsyncCreatable.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import React from 'react';
22
import Select from './Select';
3+
import Async from './Async';
4+
import Creatable from './Creatable';
35

46
function reduce(obj, props = {}){
57
return Object.keys(obj)
@@ -18,9 +20,9 @@ class AsyncCreatableSelect extends React.Component {
1820

1921
render () {
2022
return (
21-
<Select.Async {...this.props}>
23+
<Async {...this.props}>
2224
{(asyncProps) => (
23-
<Select.Creatable {...this.props}>
25+
<Creatable {...this.props}>
2426
{(creatableProps) => (
2527
<Select
2628
{...reduce(asyncProps, reduce(creatableProps, {}))}
@@ -35,12 +37,11 @@ class AsyncCreatableSelect extends React.Component {
3537
}}
3638
/>
3739
)}
38-
</Select.Creatable>
40+
</Creatable>
3941
)}
40-
</Select.Async>
42+
</Async>
4143
);
4244
}
4345
};
4446

4547
module.exports = AsyncCreatableSelect;
46-

src/Select.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ import defaultFilterOptions from './utils/defaultFilterOptions';
1515
import defaultMenuRenderer from './utils/defaultMenuRenderer';
1616
import defaultClearRenderer from './utils/defaultClearRenderer';
1717

18-
import Async from './Async';
19-
import AsyncCreatable from './AsyncCreatable';
20-
import Creatable from './Creatable';
2118
import Option from './Option';
2219
import Value from './Value';
2320

@@ -1117,10 +1114,6 @@ Select.propTypes = {
11171114
wrapperStyle: PropTypes.object, // optional style to apply to the component wrapper
11181115
};
11191116

1120-
Select.Async = Async;
1121-
Select.AsyncCreatable = AsyncCreatable;
1122-
Select.Creatable = Creatable;
1123-
11241117
Select.defaultProps = {
11251118
addLabelText: 'Add "{label}"?',
11261119
arrowRenderer: defaultArrowRenderer,

src/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Select from './Select';
2+
import Async from './Async';
3+
import AsyncCreatable from './AsyncCreatable';
4+
import Creatable from './Creatable';
5+
6+
Select.Async = Async;
7+
Select.AsyncCreatable = AsyncCreatable;
8+
Select.Creatable = Creatable;
9+
10+
export default Select;
11+
export {
12+
Async,
13+
AsyncCreatable,
14+
Creatable
15+
};

test/Async-test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var ReactDOM = require('react-dom');
2020
var TestUtils = require('react-addons-test-utils');
2121
var sinon = require('sinon');
2222

23-
var Select = require('../src/Select');
23+
var Select = require('../src');
2424

2525
describe('Async', () => {
2626
let asyncInstance, asyncNode, filterInputNode, loadOptions;
@@ -31,8 +31,8 @@ describe('Async', () => {
3131
<Select.Async
3232
autoload={false}
3333
openOnFocus
34-
{...props}
3534
loadOptions={loadOptions}
35+
{...props}
3636
/>
3737
);
3838
asyncNode = ReactDOM.findDOMNode(asyncInstance);
@@ -438,13 +438,13 @@ describe('Async', () => {
438438
describe('.focus()', () => {
439439
beforeEach(() => {
440440
createControl({});
441+
TestUtils.Simulate.blur(filterInputNode);
441442
});
442443

443444
it('focuses the search input', () => {
444-
var input = asyncNode.querySelector('input');
445-
expect(input, 'not to equal', document.activeElement);
445+
expect(filterInputNode, 'not to equal', document.activeElement);
446446
asyncInstance.focus();
447-
expect(input, 'to equal', document.activeElement);
447+
expect(filterInputNode, 'to equal', document.activeElement);
448448
});
449449
});
450450

test/AsyncCreatable-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var React = require('react');
1616
var ReactDOM = require('react-dom');
1717
var TestUtils = require('react-addons-test-utils');
1818
var sinon = require('sinon');
19-
var Select = require('../src/Select');
19+
var Select = require('../src');
2020

2121
describe('AsyncCreatable', () => {
2222
let creatableInstance, creatableNode, filterInputNode, loadOptions, renderer;

test/Creatable-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var expect = unexpected
1616
var React = require('react');
1717
var ReactDOM = require('react-dom');
1818
var TestUtils = require('react-addons-test-utils');
19-
var Select = require('../src/Select');
19+
var Select = require('../src');
2020

2121
describe('Creatable', () => {
2222
let creatableInstance, creatableNode, filterInputNode, innerSelectInstance, renderer;

test/Select-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,7 +2479,7 @@ describe('Select', () => {
24792479
expect(spyFilterOption, 'was called with', defaultOptions[1], '');
24802480
expect(spyFilterOption, 'was called with', defaultOptions[2], '');
24812481
expect(spyFilterOption, 'was called with', defaultOptions[3], '');
2482-
});
2482+
}).timeout(5000);
24832483

24842484
describe('when entering text', () => {
24852485

@@ -2497,7 +2497,7 @@ describe('Select', () => {
24972497
expect(spyFilterOption, 'was called with', defaultOptions[1], 'xyz');
24982498
expect(spyFilterOption, 'was called with', defaultOptions[2], 'xyz');
24992499
expect(spyFilterOption, 'was called with', defaultOptions[3], 'xyz');
2500-
});
2500+
}).timeout(5000);
25012501

25022502
it('only shows the filtered option', () => {
25032503

0 commit comments

Comments
 (0)