Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions dist/react-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ var Select = React.createClass({
inputProps: React.PropTypes.object, // custom attributes for the Input (in the Select-control) e.g: {'data-foo': 'bar'}
matchPos: React.PropTypes.string, // (any|start) match the start or entire string when filtering
matchProp: React.PropTypes.string, // (any|label|value) which option property to filter on
maxOptions: React.PropTypes.number, // max number of results to show
multi: React.PropTypes.bool, // multi-value input
name: React.PropTypes.string, // field name, for hidden <input /> tag
newOptionCreator: React.PropTypes.func, // factory to create new options when allowCreate set
Expand Down Expand Up @@ -140,6 +141,7 @@ var Select = React.createClass({
inputProps: {},
matchPos: 'any',
matchProp: 'any',
maxOptions: undefined,
name: undefined,
newOptionCreator: undefined,
noResultsText: 'No results found',
Expand Down Expand Up @@ -643,12 +645,19 @@ var Select = React.createClass({
},

filterOptions: function filterOptions(options, values) {
var _this7 = this;

var filterValue = this._optionsFilterString;
var exclude = (values || this.state.values).map(function (i) {
return i.value;
});
var limitResults = function limitResults(result) {
return (result || []).slice(0, _this7.props.maxOptions);
};

if (this.props.filterOptions) {
return this.props.filterOptions.call(this, options, filterValue, exclude);
var filteredOptions = this.props.filterOptions.call(this, options, filterValue, exclude);
return limitResults(filteredOptions);
} else {
var filterOption = function filterOption(op) {
if (this.props.multi && exclude.indexOf(op.value) > -1) return false;
Expand All @@ -662,7 +671,8 @@ var Select = React.createClass({
}
return !filterValue || this.props.matchPos === 'start' ? this.props.matchProp !== 'label' && valueTest.substr(0, filterValue.length) === filterValue || this.props.matchProp !== 'value' && labelTest.substr(0, filterValue.length) === filterValue : this.props.matchProp !== 'label' && valueTest.indexOf(filterValue) >= 0 || this.props.matchProp !== 'value' && labelTest.indexOf(filterValue) >= 0;
};
return (options || []).filter(filterOption, this);
var filterOptions = (options || []).filter(filterOption, this);
return limitResults(filterOptions);
}
},

Expand Down
2 changes: 1 addition & 1 deletion dist/react-select.min.js

Large diffs are not rendered by default.

14 changes: 12 additions & 2 deletions examples/dist/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ var Select = React.createClass({
inputProps: React.PropTypes.object, // custom attributes for the Input (in the Select-control) e.g: {'data-foo': 'bar'}
matchPos: React.PropTypes.string, // (any|start) match the start or entire string when filtering
matchProp: React.PropTypes.string, // (any|label|value) which option property to filter on
maxOptions: React.PropTypes.number, // max number of results to show
multi: React.PropTypes.bool, // multi-value input
name: React.PropTypes.string, // field name, for hidden <input /> tag
newOptionCreator: React.PropTypes.func, // factory to create new options when allowCreate set
Expand Down Expand Up @@ -253,6 +254,7 @@ var Select = React.createClass({
inputProps: {},
matchPos: 'any',
matchProp: 'any',
maxOptions: undefined,
name: undefined,
newOptionCreator: undefined,
noResultsText: 'No results found',
Expand Down Expand Up @@ -756,12 +758,19 @@ var Select = React.createClass({
},

filterOptions: function filterOptions(options, values) {
var _this7 = this;

var filterValue = this._optionsFilterString;
var exclude = (values || this.state.values).map(function (i) {
return i.value;
});
var limitResults = function limitResults(result) {
return (result || []).slice(0, _this7.props.maxOptions);
};

if (this.props.filterOptions) {
return this.props.filterOptions.call(this, options, filterValue, exclude);
var filteredOptions = this.props.filterOptions.call(this, options, filterValue, exclude);
return limitResults(filteredOptions);
} else {
var filterOption = function filterOption(op) {
if (this.props.multi && exclude.indexOf(op.value) > -1) return false;
Expand All @@ -775,7 +784,8 @@ var Select = React.createClass({
}
return !filterValue || this.props.matchPos === 'start' ? this.props.matchProp !== 'label' && valueTest.substr(0, filterValue.length) === filterValue || this.props.matchProp !== 'value' && labelTest.substr(0, filterValue.length) === filterValue : this.props.matchProp !== 'label' && valueTest.indexOf(filterValue) >= 0 || this.props.matchProp !== 'value' && labelTest.indexOf(filterValue) >= 0;
};
return (options || []).filter(filterOption, this);
var filterOptions = (options || []).filter(filterOption, this);
return limitResults(filterOptions);
}
},

Expand Down
5 changes: 4 additions & 1 deletion examples/dist/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -19694,10 +19694,12 @@ var AutosizeInput = React.createClass({
var widthNode = React.findDOMNode(this.refs.sizer);
widthNode.style.fontSize = inputStyle.fontSize;
widthNode.style.fontFamily = inputStyle.fontFamily;
widthNode.style.letterSpacing = inputStyle.letterSpacing;
if (this.props.placeholder) {
var placeholderNode = React.findDOMNode(this.refs.placeholderSizer);
placeholderNode.style.fontSize = inputStyle.fontSize;
placeholderNode.style.fontFamily = inputStyle.fontFamily;
placeholderNode.style.letterSpacing = inputStyle.letterSpacing;
}
},
updateInputWidth: function updateInputWidth() {
Expand Down Expand Up @@ -19732,8 +19734,9 @@ var AutosizeInput = React.createClass({
var escapedValue = (this.props.value || '').replace(/\&/g, '&amp;').replace(/ /g, '&nbsp;').replace(/\</g, '&lt;').replace(/\>/g, '&gt;');
var wrapperStyle = this.props.style || {};
wrapperStyle.display = 'inline-block';
var inputStyle = this.props.inputStyle || {};
var inputStyle = _extends({}, this.props.inputStyle);
inputStyle.width = this.state.inputWidth;
inputStyle.boxSizing = 'content-box';
var placeholder = this.props.placeholder ? React.createElement(
'div',
{ ref: 'placeholderSizer', style: sizerStyle },
Expand Down
14 changes: 12 additions & 2 deletions examples/dist/standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ var Select = React.createClass({
inputProps: React.PropTypes.object, // custom attributes for the Input (in the Select-control) e.g: {'data-foo': 'bar'}
matchPos: React.PropTypes.string, // (any|start) match the start or entire string when filtering
matchProp: React.PropTypes.string, // (any|label|value) which option property to filter on
maxOptions: React.PropTypes.number, // max number of results to show
multi: React.PropTypes.bool, // multi-value input
name: React.PropTypes.string, // field name, for hidden <input /> tag
newOptionCreator: React.PropTypes.func, // factory to create new options when allowCreate set
Expand Down Expand Up @@ -140,6 +141,7 @@ var Select = React.createClass({
inputProps: {},
matchPos: 'any',
matchProp: 'any',
maxOptions: undefined,
name: undefined,
newOptionCreator: undefined,
noResultsText: 'No results found',
Expand Down Expand Up @@ -643,12 +645,19 @@ var Select = React.createClass({
},

filterOptions: function filterOptions(options, values) {
var _this7 = this;

var filterValue = this._optionsFilterString;
var exclude = (values || this.state.values).map(function (i) {
return i.value;
});
var limitResults = function limitResults(result) {
return (result || []).slice(0, _this7.props.maxOptions);
};

if (this.props.filterOptions) {
return this.props.filterOptions.call(this, options, filterValue, exclude);
var filteredOptions = this.props.filterOptions.call(this, options, filterValue, exclude);
return limitResults(filteredOptions);
} else {
var filterOption = function filterOption(op) {
if (this.props.multi && exclude.indexOf(op.value) > -1) return false;
Expand All @@ -662,7 +671,8 @@ var Select = React.createClass({
}
return !filterValue || this.props.matchPos === 'start' ? this.props.matchProp !== 'label' && valueTest.substr(0, filterValue.length) === filterValue || this.props.matchProp !== 'value' && labelTest.substr(0, filterValue.length) === filterValue : this.props.matchProp !== 'label' && valueTest.indexOf(filterValue) >= 0 || this.props.matchProp !== 'value' && labelTest.indexOf(filterValue) >= 0;
};
return (options || []).filter(filterOption, this);
var filterOptions = (options || []).filter(filterOption, this);
return limitResults(filterOptions);
}
},

Expand Down
14 changes: 12 additions & 2 deletions lib/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var Select = React.createClass({
inputProps: React.PropTypes.object, // custom attributes for the Input (in the Select-control) e.g: {'data-foo': 'bar'}
matchPos: React.PropTypes.string, // (any|start) match the start or entire string when filtering
matchProp: React.PropTypes.string, // (any|label|value) which option property to filter on
maxOptions: React.PropTypes.number, // max number of results to show
multi: React.PropTypes.bool, // multi-value input
name: React.PropTypes.string, // field name, for hidden <input /> tag
newOptionCreator: React.PropTypes.func, // factory to create new options when allowCreate set
Expand Down Expand Up @@ -77,6 +78,7 @@ var Select = React.createClass({
inputProps: {},
matchPos: 'any',
matchProp: 'any',
maxOptions: undefined,
name: undefined,
newOptionCreator: undefined,
noResultsText: 'No results found',
Expand Down Expand Up @@ -580,12 +582,19 @@ var Select = React.createClass({
},

filterOptions: function filterOptions(options, values) {
var _this7 = this;

var filterValue = this._optionsFilterString;
var exclude = (values || this.state.values).map(function (i) {
return i.value;
});
var limitResults = function limitResults(result) {
return (result || []).slice(0, _this7.props.maxOptions);
};

if (this.props.filterOptions) {
return this.props.filterOptions.call(this, options, filterValue, exclude);
var filteredOptions = this.props.filterOptions.call(this, options, filterValue, exclude);
return limitResults(filteredOptions);
} else {
var filterOption = function filterOption(op) {
if (this.props.multi && exclude.indexOf(op.value) > -1) return false;
Expand All @@ -599,7 +608,8 @@ var Select = React.createClass({
}
return !filterValue || this.props.matchPos === 'start' ? this.props.matchProp !== 'label' && valueTest.substr(0, filterValue.length) === filterValue || this.props.matchProp !== 'value' && labelTest.substr(0, filterValue.length) === filterValue : this.props.matchProp !== 'label' && valueTest.indexOf(filterValue) >= 0 || this.props.matchProp !== 'value' && labelTest.indexOf(filterValue) >= 0;
};
return (options || []).filter(filterOption, this);
var filterOptions = (options || []).filter(filterOption, this);
return limitResults(filterOptions);
}
},

Expand Down
10 changes: 8 additions & 2 deletions src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var Select = React.createClass({
inputProps: React.PropTypes.object, // custom attributes for the Input (in the Select-control) e.g: {'data-foo': 'bar'}
matchPos: React.PropTypes.string, // (any|start) match the start or entire string when filtering
matchProp: React.PropTypes.string, // (any|label|value) which option property to filter on
maxOptions: React.PropTypes.number, // max number of results to show
multi: React.PropTypes.bool, // multi-value input
name: React.PropTypes.string, // field name, for hidden <input /> tag
newOptionCreator: React.PropTypes.func, // factory to create new options when allowCreate set
Expand Down Expand Up @@ -73,6 +74,7 @@ var Select = React.createClass({
inputProps: {},
matchPos: 'any',
matchProp: 'any',
maxOptions: undefined,
name: undefined,
newOptionCreator: undefined,
noResultsText: 'No results found',
Expand Down Expand Up @@ -567,8 +569,11 @@ var Select = React.createClass({
var exclude = (values || this.state.values).map(function(i) {
return i.value;
});
var limitResults = (result) => (result || []).slice(0, this.props.maxOptions);

if (this.props.filterOptions) {
return this.props.filterOptions.call(this, options, filterValue, exclude);
var filteredOptions = this.props.filterOptions.call(this, options, filterValue, exclude);
return limitResults(filteredOptions);
} else {
var filterOption = function(op) {
if (this.props.multi && exclude.indexOf(op.value) > -1) return false;
Expand All @@ -587,7 +592,8 @@ var Select = React.createClass({
(this.props.matchProp !== 'value' && labelTest.indexOf(filterValue) >= 0)
);
};
return (options || []).filter(filterOption, this);
var filterOptions = (options || []).filter(filterOption, this);
return limitResults(filterOptions);
}
},

Expand Down
24 changes: 22 additions & 2 deletions test/Select-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2037,7 +2037,7 @@ describe('Select', function() {
});
});

describe('custom filterOptions function', function () {
describe.only('custom filterOptions function', function () {

var spyFilterOptions;

Expand Down Expand Up @@ -2802,14 +2802,34 @@ describe('Select', function() {
});
});
});


describe('maxOptions', function () {
var maxOptions = 2;

beforeEach(function () {
instance = createControl({
options: defaultOptions,
maxOptions: maxOptions,
});
});


it('limits the number of options show', function() {
TestUtils.Simulate.mouseDown(React.findDOMNode(instance).querySelector('.Select-control'));
var options = React.findDOMNode(instance).querySelectorAll('.Select-option');
expect(options, 'to have length', 2);
});

});
});

describe('clicking outside', function () {

beforeEach(function () {

instance = createControl({
options: defaultOptions
options: defaultOptions,
});
});

Expand Down