Skip to content

Commit

Permalink
Implementing matchPos property, fixes JedWatson#23
Browse files Browse the repository at this point in the history
  • Loading branch information
JedWatson authored and CoreyTrombley committed Jan 5, 2015
1 parent 87d271d commit c307a6e
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/Select.js
Expand Up @@ -20,7 +20,8 @@ var Select = React.createClass({
placeholder: React.PropTypes.string, // field placeholder, displayed when there's no value
name: React.PropTypes.string, // field name, for hidden <input /> tag
onChange: React.PropTypes.func, // onChange handler: function(newValue) {}
className: React.PropTypes.string // className for the outer element
className: React.PropTypes.string, // className for the outer element
matchPos: React.PropTypes.string // (any|start) match the start or entire string when filtering
},

getDefaultProps: function() {
Expand All @@ -33,7 +34,8 @@ var Select = React.createClass({
placeholder: '',
name: undefined,
onChange: undefined,
className: undefined
className: undefined,
matchPos: 'any'
};
},

Expand Down Expand Up @@ -322,10 +324,13 @@ var Select = React.createClass({
});
var filterOption = function(op) {
if (this.props.multi && _.contains(exclude, op.value)) return false;
return (
!filterValue
|| op.value.toLowerCase().indexOf(filterValue.toLowerCase()) >= 0
|| op.label.toLowerCase().indexOf(filterValue.toLowerCase()) >= 0
if (this.props.filterOption) return this.props.filterOption.call(this, option, filterValue);
return !filterValue || (this.props.matchPos === 'start') ? (
op.value.toLowerCase().substr(0, filterValue.length) === filterValue ||
op.label.toLowerCase().substr(0, filterValue.length) === filterValue
) : (
op.value.toLowerCase().indexOf(filterValue.toLowerCase()) >= 0 ||
op.label.toLowerCase().indexOf(filterValue.toLowerCase()) >= 0
);
}
return _.filter(options, filterOption, this);
Expand Down

0 comments on commit c307a6e

Please sign in to comment.