Skip to content

Commit e1d8ee4

Browse files
author
Trevor Burnham
committed
Trigger closeMenu when isOpen changes from true to false
This ensures that the input is reset if onCloseResetsInput is true.
1 parent ea40ef1 commit e1d8ee4

File tree

7 files changed

+62
-10
lines changed

7 files changed

+62
-10
lines changed

dist/react-select-plus.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var propTypes = {
4141
loadingPlaceholder: _react2['default'].PropTypes.oneOfType([// replaces the placeholder while options are loading
4242
_react2['default'].PropTypes.string, _react2['default'].PropTypes.node]),
4343
loadOptions: _react2['default'].PropTypes.func.isRequired, // callback to load options asynchronously; (inputValue: string, callback: Function): ?Promise
44+
multi: _react2['default'].PropTypes.bool, // multi-value input
4445
options: _react.PropTypes.array.isRequired, // array of options
4546
placeholder: _react2['default'].PropTypes.oneOfType([// field placeholder, displayed when there's no value (shared with Select)
4647
_react2['default'].PropTypes.string, _react2['default'].PropTypes.node]),
@@ -1161,6 +1162,10 @@ var Select = _react2['default'].createClass({
11611162

11621163
var valueArray = this.getValueArray(nextProps.value, nextProps);
11631164

1165+
if (!nextProps.isOpen && this.props.isOpen) {
1166+
this.closeMenu();
1167+
}
1168+
11641169
if (nextProps.required) {
11651170
this.setState({
11661171
required: this.handleRequired(valueArray[0], nextProps.multi)
@@ -1337,7 +1342,7 @@ var Select = _react2['default'].createClass({
13371342
});
13381343
} else {
13391344
// otherwise, focus the input and open the menu
1340-
this._openAfterFocus = true;
1345+
this._openAfterFocus = this.props.openOnFocus;
13411346
this.focus();
13421347
}
13431348
},
@@ -2113,7 +2118,14 @@ var Select = _react2['default'].createClass({
21132118

21142119
var focusedOption = this.state.focusedOption || selectedOption;
21152120
if (focusedOption && !focusedOption.disabled) {
2116-
var focusedOptionIndex = options.indexOf(focusedOption);
2121+
var focusedOptionIndex = -1;
2122+
options.some(function (option, index) {
2123+
var isOptionEqual = option.value === focusedOption.value;
2124+
if (isOptionEqual) {
2125+
focusedOptionIndex = index;
2126+
}
2127+
return isOptionEqual;
2128+
});
21172129
if (focusedOptionIndex !== -1) {
21182130
return focusedOptionIndex;
21192131
}

dist/react-select-plus.min.js

Lines changed: 2 additions & 2 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: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ var propTypes = {
4040
loadingPlaceholder: _react2['default'].PropTypes.oneOfType([// replaces the placeholder while options are loading
4141
_react2['default'].PropTypes.string, _react2['default'].PropTypes.node]),
4242
loadOptions: _react2['default'].PropTypes.func.isRequired, // callback to load options asynchronously; (inputValue: string, callback: Function): ?Promise
43+
multi: _react2['default'].PropTypes.bool, // multi-value input
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]),
@@ -1461,6 +1462,10 @@ var Select = _react2['default'].createClass({
14611462

14621463
var valueArray = this.getValueArray(nextProps.value, nextProps);
14631464

1465+
if (!nextProps.isOpen && this.props.isOpen) {
1466+
this.closeMenu();
1467+
}
1468+
14641469
if (nextProps.required) {
14651470
this.setState({
14661471
required: this.handleRequired(valueArray[0], nextProps.multi)
@@ -1637,7 +1642,7 @@ var Select = _react2['default'].createClass({
16371642
});
16381643
} else {
16391644
// otherwise, focus the input and open the menu
1640-
this._openAfterFocus = true;
1645+
this._openAfterFocus = this.props.openOnFocus;
16411646
this.focus();
16421647
}
16431648
},
@@ -2413,7 +2418,14 @@ var Select = _react2['default'].createClass({
24132418

24142419
var focusedOption = this.state.focusedOption || selectedOption;
24152420
if (focusedOption && !focusedOption.disabled) {
2416-
var focusedOptionIndex = options.indexOf(focusedOption);
2421+
var focusedOptionIndex = -1;
2422+
options.some(function (option, index) {
2423+
var isOptionEqual = option.value === focusedOption.value;
2424+
if (isOptionEqual) {
2425+
focusedOptionIndex = index;
2426+
}
2427+
return isOptionEqual;
2428+
});
24172429
if (focusedOptionIndex !== -1) {
24182430
return focusedOptionIndex;
24192431
}

examples/dist/standalone.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var propTypes = {
4141
loadingPlaceholder: _react2['default'].PropTypes.oneOfType([// replaces the placeholder while options are loading
4242
_react2['default'].PropTypes.string, _react2['default'].PropTypes.node]),
4343
loadOptions: _react2['default'].PropTypes.func.isRequired, // callback to load options asynchronously; (inputValue: string, callback: Function): ?Promise
44+
multi: _react2['default'].PropTypes.bool, // multi-value input
4445
options: _react.PropTypes.array.isRequired, // array of options
4546
placeholder: _react2['default'].PropTypes.oneOfType([// field placeholder, displayed when there's no value (shared with Select)
4647
_react2['default'].PropTypes.string, _react2['default'].PropTypes.node]),
@@ -1161,6 +1162,10 @@ var Select = _react2['default'].createClass({
11611162

11621163
var valueArray = this.getValueArray(nextProps.value, nextProps);
11631164

1165+
if (!nextProps.isOpen && this.props.isOpen) {
1166+
this.closeMenu();
1167+
}
1168+
11641169
if (nextProps.required) {
11651170
this.setState({
11661171
required: this.handleRequired(valueArray[0], nextProps.multi)
@@ -1337,7 +1342,7 @@ var Select = _react2['default'].createClass({
13371342
});
13381343
} else {
13391344
// otherwise, focus the input and open the menu
1340-
this._openAfterFocus = true;
1345+
this._openAfterFocus = this.props.openOnFocus;
13411346
this.focus();
13421347
}
13431348
},
@@ -2113,7 +2118,14 @@ var Select = _react2['default'].createClass({
21132118

21142119
var focusedOption = this.state.focusedOption || selectedOption;
21152120
if (focusedOption && !focusedOption.disabled) {
2116-
var focusedOptionIndex = options.indexOf(focusedOption);
2121+
var focusedOptionIndex = -1;
2122+
options.some(function (option, index) {
2123+
var isOptionEqual = option.value === focusedOption.value;
2124+
if (isOptionEqual) {
2125+
focusedOptionIndex = index;
2126+
}
2127+
return isOptionEqual;
2128+
});
21172129
if (focusedOptionIndex !== -1) {
21182130
return focusedOptionIndex;
21192131
}

lib/Async.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ var propTypes = {
3939
loadingPlaceholder: _react2['default'].PropTypes.oneOfType([// replaces the placeholder while options are loading
4040
_react2['default'].PropTypes.string, _react2['default'].PropTypes.node]),
4141
loadOptions: _react2['default'].PropTypes.func.isRequired, // callback to load options asynchronously; (inputValue: string, callback: Function): ?Promise
42+
multi: _react2['default'].PropTypes.bool, // multi-value input
4243
options: _react.PropTypes.array.isRequired, // array of options
4344
placeholder: _react2['default'].PropTypes.oneOfType([// field placeholder, displayed when there's no value (shared with Select)
4445
_react2['default'].PropTypes.string, _react2['default'].PropTypes.node]),

lib/Select.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ var Select = _react2['default'].createClass({
275275

276276
var valueArray = this.getValueArray(nextProps.value, nextProps);
277277

278+
if (!nextProps.isOpen && this.props.isOpen) {
279+
this.closeMenu();
280+
}
281+
278282
if (nextProps.required) {
279283
this.setState({
280284
required: this.handleRequired(valueArray[0], nextProps.multi)
@@ -1227,7 +1231,14 @@ var Select = _react2['default'].createClass({
12271231

12281232
var focusedOption = this.state.focusedOption || selectedOption;
12291233
if (focusedOption && !focusedOption.disabled) {
1230-
var focusedOptionIndex = options.indexOf(focusedOption);
1234+
var focusedOptionIndex = -1;
1235+
options.some(function (option, index) {
1236+
var isOptionEqual = option.value === focusedOption.value;
1237+
if (isOptionEqual) {
1238+
focusedOptionIndex = index;
1239+
}
1240+
return isOptionEqual;
1241+
});
12311242
if (focusedOptionIndex !== -1) {
12321243
return focusedOptionIndex;
12331244
}
@@ -1346,4 +1357,4 @@ var Select = _react2['default'].createClass({
13461357
});
13471358

13481359
exports['default'] = Select;
1349-
module.exports = exports['default'];
1360+
module.exports = exports['default'];

src/Select.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ const Select = React.createClass({
222222

223223
const valueArray = this.getValueArray(nextProps.value, nextProps);
224224

225+
if (!nextProps.isOpen && this.props.isOpen) {
226+
this.closeMenu();
227+
}
228+
225229
if (nextProps.required) {
226230
this.setState({
227231
required: this.handleRequired(valueArray[0], nextProps.multi),

0 commit comments

Comments
 (0)