Skip to content

Commit

Permalink
fix #134
Browse files Browse the repository at this point in the history
  • Loading branch information
yiminghe committed Nov 11, 2016
1 parent 4441b58 commit 3ada48a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rc-select",
"version": "6.6.5",
"version": "6.6.7",
"description": "React Select",
"keywords": [
"react",
Expand Down
37 changes: 26 additions & 11 deletions src/Select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ const Select = React.createClass({
};
},

componentWillMount() {
this.adjustOpenState();
},

componentWillReceiveProps(nextProps) {
if ('value' in nextProps) {
let value = toArray(nextProps.value);
Expand All @@ -144,15 +148,19 @@ const Select = React.createClass({
value,
});
if (nextProps.combobox) {
const options = this.renderFilterOptions();
this.setState({
inputValue: value.length ? this.getLabelFromProps(nextProps, value[0].key) : '',
open: this.state.open && !!options.length,
});
}
}
},

componentWillUpdate(nextProps, nextState) {
this.props = nextProps;
this.state = nextState;
this.adjustOpenState();
},

componentDidUpdate() {
const { state, props } = this;
if (state.open && isMultipleOrTags(props)) {
Expand Down Expand Up @@ -691,6 +699,20 @@ const Select = React.createClass({
return nextValue;
},

adjustOpenState() {
let { open } = this.state;
let options = [];
if (open) {
options = this.renderFilterOptions();
}
this._options = options;
if (open &&
(isMultipleOrTagsOrCombobox(this.props) || !this.props.showSearch) && !options.length) {
open = false;
}
this.state.open = open;
},

renderTopControlNode() {
const { value, open, inputValue } = this.state;
const props = this.props;
Expand Down Expand Up @@ -806,15 +828,8 @@ const Select = React.createClass({
const { className, disabled, allowClear, prefixCls } = props;
const ctrlNode = this.renderTopControlNode();
let extraSelectionProps = {};
let { open } = this.state;
let options = [];
if (open) {
options = this.renderFilterOptions();
}
this._options = options;
if (open && (isMultipleOrTagsOrCombobox(props) || !props.showSearch) && !options.length) {
open = false;
}
const { open } = this.state;
const options = this._options;
if (!isMultipleOrTagsOrCombobox(props)) {
extraSelectionProps = {
onKeyDown: this.onKeyDown,
Expand Down

0 comments on commit 3ada48a

Please sign in to comment.