Skip to content

Commit 98b851b

Browse files
committed
add prop to case sensitive
1 parent 04e7838 commit 98b851b

4 files changed

Lines changed: 32 additions & 13 deletions

File tree

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ Either an `[String]` or a `String`. Will be use by the `filter` method if no arg
8888

8989
##### throttle
9090

91-
Reduce call frequency to the `onChange` function (in ms). Default is 200.
91+
Reduce call frequency to the `onChange` function (in ms). Default is `200`.
92+
93+
##### caseSensitive
94+
95+
Define if the search should be case sensitive. Default is `false`
9296

9397
### Methods
9498

@@ -100,7 +104,7 @@ If an array `keys` is an array, the function will return true if at least one of
100104

101105
### Static Methods
102106

103-
##### filter(searchTerm, [keys])
107+
##### filter(searchTerm, [keys], [caseSensitive])
104108

105109
Return a function which can be used to filter an array. `searchTerm` can be a `regex` or a `String`. `keys` can be `String`, `[String]` or `null`.
106110

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"react-search-input.js",
55
"react-search-input.css"
66
],
7-
"version": "0.2.3",
7+
"version": "0.2.4",
88
"homepage": "https://github.com/enki-com/react-search-input",
99
"description": "Simple react.js component for a search input, providing a filter function.",
1010
"keywords": [

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-search-input",
3-
"version": "0.2.3",
3+
"version": "0.2.4",
44
"description": "Simple react.js component for a search input, providing a filter function.",
55
"main": "react-search-input.js",
66
"dependencies": {

react-search-input.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,23 @@
1212
var Search = React.createClass({
1313
propTypes: {
1414
className: React.PropTypes.string,
15-
onChange: React.PropTypes.func
15+
onChange: React.PropTypes.func,
16+
caseSensitive: React.PropTypes.bool,
17+
throttle: React.PropTypes.number,
18+
filterKeys: React.PropTypes.oneOf([
19+
React.PropTypes.string,
20+
React.PropTypes.arrayOf(React.PropTypes.string)
21+
])
22+
23+
},
24+
25+
getDefaultProps: function() {
26+
return {
27+
className: '',
28+
onChange: function() {},
29+
caseSensitive: false,
30+
throttle: 200
31+
}
1632
},
1733

1834
getInitialState: function() {
@@ -42,26 +58,25 @@
4258
if (this._throttleTimeout) {
4359
clearTimeout(this._throttleTimeout);
4460
}
45-
this._throttleTimeout = setTimeout(function() {
46-
if (this.props.onChange) {
47-
this.props.onChange(searchTerm);
48-
}
49-
}.bind(this), this.props.throttle);
61+
this._throttleTimeout = setTimeout(this.props.onChange, this.props.throttle, searchTerm);
5062
}.bind(this));
5163
},
5264

5365
filter: function(keys) {
5466
return Search.filter(this.state.searchTerm,
55-
keys || this.props.filterKeys);
67+
keys || this.props.filterKeys, this.props.caseSensitive);
5668
},
5769

5870
statics: {
59-
filter: function(term, keys) {
71+
filter: function(term, keys, caseSensitive) {
6072
return function(item) {
6173
if (term === '') {return true;}
6274
// escape special symbols to ensure `term` is a valid regex
6375
//var escapedTerm = term.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
64-
term = term.toLowerCase();
76+
77+
if (!caseSensitive) {
78+
term = term.toLowerCase();
79+
}
6580

6681
if (keys) {
6782
if( typeof keys === 'string' ) {

0 commit comments

Comments
 (0)