Skip to content

Commit 426e282

Browse files
author
Brian Vaughn
committed
Fixed linting issues
1 parent a13246b commit 426e282

File tree

8 files changed

+1053
-677
lines changed

8 files changed

+1053
-677
lines changed

examples/dist/app.js

Lines changed: 14 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/dist/bundle.js

Lines changed: 105 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/dist/common.js

Lines changed: 825 additions & 612 deletions
Large diffs are not rendered by default.

examples/dist/example.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@
210210
margin: -1px;
211211
clip: rect(0, 0, 0, 0);
212212
overflow: hidden;
213+
float: left;
213214
}
214215
@-webkit-keyframes Select-animation-fadeIn {
215216
from {

examples/dist/standalone.js

Lines changed: 103 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,26 @@ var propTypes = {
3838
children: _react2['default'].PropTypes.func.isRequired, // Child function responsible for creating the inner Select component; (props: Object): PropTypes.element
3939
ignoreAccents: _react2['default'].PropTypes.bool, // strip diacritics when filtering; defaults to true
4040
ignoreCase: _react2['default'].PropTypes.bool, // perform case-insensitive filtering; defaults to true
41-
loadingPlaceholder: _react.PropTypes.string.isRequired, // replaces the placeholder while options are loading
41+
loadingPlaceholder: _react2['default'].PropTypes.oneOfType([// replaces the placeholder while options are loading
42+
_react2['default'].PropTypes.string, _react2['default'].PropTypes.node]),
4243
loadOptions: _react2['default'].PropTypes.func.isRequired, // callback to load options asynchronously; (inputValue: string, callback: Function): ?Promise
4344
options: _react.PropTypes.array.isRequired, // array of options
4445
placeholder: _react2['default'].PropTypes.oneOfType([// field placeholder, displayed when there's no value (shared with Select)
4546
_react2['default'].PropTypes.string, _react2['default'].PropTypes.node]),
47+
noResultsText: _react2['default'].PropTypes.oneOfType([// field noResultsText, displayed when no options come back from the server
48+
_react2['default'].PropTypes.string, _react2['default'].PropTypes.node]),
49+
onChange: _react2['default'].PropTypes.func, // onChange handler: function (newValue) {}
4650
searchPromptText: _react2['default'].PropTypes.oneOfType([// label to prompt for search input
47-
_react2['default'].PropTypes.string, _react2['default'].PropTypes.node])
48-
};
51+
_react2['default'].PropTypes.string, _react2['default'].PropTypes.node]),
52+
onInputChange: _react2['default'].PropTypes.func, // optional for keeping track of what is being typed
53+
value: _react2['default'].PropTypes.any };
54+
55+
// initial field value
56+
var defaultCache = {};
4957

5058
var defaultProps = {
5159
autoload: true,
52-
cache: {},
60+
cache: defaultCache,
5361
children: defaultChildren,
5462
ignoreAccents: true,
5563
ignoreCase: true,
@@ -75,6 +83,11 @@ var Async = (function (_Component) {
7583
}
7684

7785
_createClass(Async, [{
86+
key: 'componentWillMount',
87+
value: function componentWillMount() {
88+
this.cache = this.props.cache === defaultCache ? {} : this.props.cache;
89+
}
90+
}, {
7891
key: 'componentDidMount',
7992
value: function componentDidMount() {
8093
var autoload = this.props.autoload;
@@ -95,14 +108,19 @@ var Async = (function (_Component) {
95108
}
96109
});
97110
}
111+
}, {
112+
key: 'clearOptions',
113+
value: function clearOptions() {
114+
this.setState({ options: [] });
115+
}
98116
}, {
99117
key: 'loadOptions',
100118
value: function loadOptions(inputValue) {
101119
var _this2 = this;
102120

103-
var _props = this.props;
104-
var cache = _props.cache;
105-
var loadOptions = _props.loadOptions;
121+
var loadOptions = this.props.loadOptions;
122+
123+
var cache = this.cache;
106124

107125
if (cache && cache.hasOwnProperty(inputValue)) {
108126
this.setState({
@@ -152,9 +170,10 @@ var Async = (function (_Component) {
152170
}, {
153171
key: '_onInputChange',
154172
value: function _onInputChange(inputValue) {
155-
var _props2 = this.props;
156-
var ignoreAccents = _props2.ignoreAccents;
157-
var ignoreCase = _props2.ignoreCase;
173+
var _props = this.props;
174+
var ignoreAccents = _props.ignoreAccents;
175+
var ignoreCase = _props.ignoreCase;
176+
var onInputChange = _props.onInputChange;
158177

159178
if (ignoreAccents) {
160179
inputValue = (0, _utilsStripDiacritics2['default'])(inputValue);
@@ -164,24 +183,65 @@ var Async = (function (_Component) {
164183
inputValue = inputValue.toLowerCase();
165184
}
166185

186+
if (onInputChange) {
187+
onInputChange(inputValue);
188+
}
189+
167190
return this.loadOptions(inputValue);
168191
}
192+
}, {
193+
key: 'inputValue',
194+
value: function inputValue() {
195+
if (this.select) {
196+
return this.select.state.inputValue;
197+
}
198+
return '';
199+
}
200+
}, {
201+
key: 'noResultsText',
202+
value: function noResultsText() {
203+
var _props2 = this.props;
204+
var loadingPlaceholder = _props2.loadingPlaceholder;
205+
var noResultsText = _props2.noResultsText;
206+
var searchPromptText = _props2.searchPromptText;
207+
var isLoading = this.state.isLoading;
208+
209+
var inputValue = this.inputValue();
210+
211+
if (isLoading) {
212+
return loadingPlaceholder;
213+
}
214+
if (inputValue && noResultsText) {
215+
return noResultsText;
216+
}
217+
return searchPromptText;
218+
}
169219
}, {
170220
key: 'render',
171221
value: function render() {
222+
var _this3 = this;
223+
172224
var _props3 = this.props;
173225
var children = _props3.children;
174226
var loadingPlaceholder = _props3.loadingPlaceholder;
175227
var placeholder = _props3.placeholder;
176-
var searchPromptText = _props3.searchPromptText;
177228
var _state = this.state;
178229
var isLoading = _state.isLoading;
179230
var options = _state.options;
180231

181232
var props = {
182-
noResultsText: isLoading ? loadingPlaceholder : searchPromptText,
233+
noResultsText: this.noResultsText(),
183234
placeholder: isLoading ? loadingPlaceholder : placeholder,
184-
options: isLoading ? [] : options
235+
options: isLoading && loadingPlaceholder ? [] : options,
236+
ref: function ref(_ref) {
237+
return _this3.select = _ref;
238+
},
239+
onChange: function onChange(newValues) {
240+
if (_this3.props.value && newValues.length > _this3.props.value.length) {
241+
_this3.clearOptions();
242+
}
243+
_this3.props.onChange(newValues);
244+
}
185245
};
186246

187247
return children(_extends({}, this.props, props, {
@@ -305,6 +365,9 @@ var Creatable = _react2['default'].createClass({
305365
// ({ label: string, labelKey: string, valueKey: string }): Object
306366
newOptionCreator: _react2['default'].PropTypes.func,
307367

368+
// input keyDown handler: function (event) {}
369+
onInputKeyDown: _react2['default'].PropTypes.func,
370+
308371
// See Select.propTypes.options
309372
options: _react2['default'].PropTypes.array,
310373

@@ -433,7 +496,9 @@ var Creatable = _react2['default'].createClass({
433496
},
434497

435498
onInputKeyDown: function onInputKeyDown(event) {
436-
var shouldKeyDownEventCreateNewOption = this.props.shouldKeyDownEventCreateNewOption;
499+
var _props3 = this.props;
500+
var shouldKeyDownEventCreateNewOption = _props3.shouldKeyDownEventCreateNewOption;
501+
var onInputKeyDown = _props3.onInputKeyDown;
437502

438503
var focusedOption = this.select.getFocusedOption();
439504

@@ -442,6 +507,8 @@ var Creatable = _react2['default'].createClass({
442507

443508
// Prevent decorated Select from doing anything additional with this keyDown event
444509
event.preventDefault();
510+
} else if (onInputKeyDown) {
511+
onInputKeyDown(event);
445512
}
446513
},
447514

@@ -456,13 +523,13 @@ var Creatable = _react2['default'].createClass({
456523
render: function render() {
457524
var _this = this;
458525

459-
var _props3 = this.props;
460-
var _props3$children = _props3.children;
461-
var children = _props3$children === undefined ? defaultChildren : _props3$children;
462-
var newOptionCreator = _props3.newOptionCreator;
463-
var shouldKeyDownEventCreateNewOption = _props3.shouldKeyDownEventCreateNewOption;
526+
var _props4 = this.props;
527+
var _props4$children = _props4.children;
528+
var children = _props4$children === undefined ? defaultChildren : _props4$children;
529+
var newOptionCreator = _props4.newOptionCreator;
530+
var shouldKeyDownEventCreateNewOption = _props4.shouldKeyDownEventCreateNewOption;
464531

465-
var restProps = _objectWithoutProperties(_props3, ['children', 'newOptionCreator', 'shouldKeyDownEventCreateNewOption']);
532+
var restProps = _objectWithoutProperties(_props4, ['children', 'newOptionCreator', 'shouldKeyDownEventCreateNewOption']);
466533

467534
var props = _extends({}, restProps, {
468535
allowCreate: true,
@@ -938,14 +1005,26 @@ var Select = _react2['default'].createClass({
9381005
},
9391006

9401007
componentWillUnmount: function componentWillUnmount() {
941-
document.removeEventListener('touchstart', this.handleTouchOutside);
1008+
if (!document.removeEventListener && document.detachEvent) {
1009+
document.detachEvent('ontouchstart', this.handleTouchOutside);
1010+
} else {
1011+
document.removeEventListener('touchstart', this.handleTouchOutside);
1012+
}
9421013
},
9431014

9441015
toggleTouchOutsideEvent: function toggleTouchOutsideEvent(enabled) {
9451016
if (enabled) {
946-
document.addEventListener('touchstart', this.handleTouchOutside);
1017+
if (!document.addEventListener && document.attachEvent) {
1018+
document.attachEvent('ontouchstart', this.handleTouchOutside);
1019+
} else {
1020+
document.addEventListener('touchstart', this.handleTouchOutside);
1021+
}
9471022
} else {
948-
document.removeEventListener('touchstart', this.handleTouchOutside);
1023+
if (!document.removeEventListener && document.detachEvent) {
1024+
document.detachEvent('ontouchstart', this.handleTouchOutside);
1025+
} else {
1026+
document.removeEventListener('touchstart', this.handleTouchOutside);
1027+
}
9491028
}
9501029
},
9511030

@@ -1601,7 +1680,7 @@ var Select = _react2['default'].createClass({
16011680
}
16021681

16031682
if (this.props.autosize) {
1604-
return _react2['default'].createElement(_reactInputAutosize2['default'], _extends({}, inputProps, { minWidth: '5px' }));
1683+
return _react2['default'].createElement(_reactInputAutosize2['default'], _extends({}, inputProps, { minWidth: '5' }));
16051684
}
16061685
return _react2['default'].createElement(
16071686
'div',

src/Async.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const propTypes = {
2222
React.PropTypes.string,
2323
React.PropTypes.node
2424
]),
25+
onChange: React.PropTypes.func, // onChange handler: function (newValue) {}
2526
searchPromptText: React.PropTypes.oneOfType([ // label to prompt for search input
2627
React.PropTypes.string,
2728
React.PropTypes.node

src/Creatable.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ const Creatable = React.createClass({
3131
// ({ label: string, labelKey: string, valueKey: string }): Object
3232
newOptionCreator: React.PropTypes.func,
3333

34+
// input keyDown handler: function (event) {}
35+
onInputKeyDown: React.PropTypes.func,
36+
3437
// See Select.propTypes.options
3538
options: React.PropTypes.array,
3639

test/Async-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ describe('Async', () => {
124124
createControl();
125125
const instance2 = asyncInstance;
126126
expect(instance1.cache !== instance2.cache, 'to equal', true);
127-
})
127+
});
128128
});
129129

130130
describe('loadOptions', () => {

0 commit comments

Comments
 (0)