Skip to content

Commit 5e1dfb0

Browse files
committed
add new props: value and placeholder
1 parent 6c6e9e4 commit 5e1dfb0

4 files changed

Lines changed: 30 additions & 12 deletions

File tree

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var App = React.createClass({
4646
var filters = ['user.name', 'subject'];
4747
mails = mails.filter(this.refs.search.filter(filters));
4848
}
49-
49+
5050
return (
5151
<div>
5252
<SearchInput ref='search' onChange={this.searchUpdated} />
@@ -61,7 +61,7 @@ var App = React.createClass({
6161
</div>
6262
);
6363
},
64-
64+
6565
searchUpdated(term) {
6666
this.setState({searchTerm: term}); // needed to force re-render
6767
}
@@ -94,6 +94,14 @@ Reduce call frequency to the `onChange` function (in ms). Default is `200`.
9494

9595
Define if the search should be case sensitive. Default is `false`
9696

97+
##### placeholder
98+
99+
Define the placeholder of the input. Default is `Search`.
100+
101+
##### value
102+
103+
Define the value of the input.
104+
97105
### Methods
98106

99107
##### filter([keys])
@@ -117,6 +125,3 @@ Look at [react-search-input.css](https://github.com/mathieudutour/react-search-i
117125
---
118126

119127
MIT Licensed
120-
121-
122-

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.7",
7+
"version": "0.2.8",
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.7",
3+
"version": "0.2.8",
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: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,46 @@
1818
filterKeys: React.PropTypes.oneOf([
1919
React.PropTypes.string,
2020
React.PropTypes.arrayOf(React.PropTypes.string)
21-
])
22-
21+
]),
22+
placeholder: React.PropTypes.string,
23+
value: React.PropTypes.string
2324
},
2425

2526
getDefaultProps: function() {
2627
return {
2728
className: '',
2829
onChange: function() {},
2930
caseSensitive: false,
30-
throttle: 200
31+
throttle: 200,
32+
placeholder: 'Search'
3133
};
3234
},
3335

3436
getInitialState: function() {
3537
return {
36-
searchTerm: ''
38+
searchTerm: this.props.value || ''
3739
};
3840
},
3941

42+
componentWillReceiveProps: function(nextProps) {
43+
if (nextProps.value && nextProps.value !== this.props.value) {
44+
var e = {
45+
target: {
46+
value: nextProps.value
47+
}
48+
};
49+
this.updateSearch(e);
50+
}
51+
},
52+
4053
render: function() {
4154
return (
4255
React.createElement('div', {className: 'search-input ' + this.props.className},
4356
React.createElement('div', {className: 'search-wrapper'},
4457
React.createElement('span', {className: 'search-icon'}, String.fromCharCode(9906)),
4558
React.createElement('input', {type: 'search', value: this.state.searchTerm,
4659
onChange: this.updateSearch, className: 'search-field',
47-
placeholder: 'Search'})
60+
placeholder: this.props.placeholder})
4861
)
4962
)
5063
);

0 commit comments

Comments
 (0)