Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Fixed issue #447 (Search box - Default Text) #852

Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ The component accepts the following props:
|**`filter`**|boolean|true|Show/hide filter icon from toolbar
|**`search`**|boolean|true|Show/hide search icon from toolbar
|**`searchText`**|string||Initial search text
|**`searchPlaceholder`**|string||Search text placeholder. [Example](https://github.com/gregnb/mui-datatables/blob/master/examples/customize-search/index.js)
|**`print`**|boolean|true|Show/hide print icon from toolbar
|**`download`**|boolean|true|Show/hide download icon from toolbar
|**`downloadOptions`**|object||Options to change the output of the CSV file. Default options: `{filename: 'tableDownload.csv', separator: ','}`
Expand Down
1 change: 1 addition & 0 deletions examples/customize-search/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class Example extends React.Component {
responsive: 'stacked',
page: 1,
searchText: this.state.searchText,
searchPlaceholder: 'Your Custom Search Placeholder',
customSearch: (searchQuery, currentRow, columns) => {
let isFound = false;
currentRow.forEach(col => {
Expand Down
1 change: 1 addition & 0 deletions src/MUIDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class MUIDataTable extends React.Component {
customSearch: PropTypes.func,
search: PropTypes.bool,
searchText: PropTypes.string,
searchPlaceholder: PropTypes.string,
print: PropTypes.bool,
viewColumns: PropTypes.bool,
download: PropTypes.bool,
Expand Down
1 change: 1 addition & 0 deletions src/components/TableSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class TableSearch extends React.Component {
onChange={this.handleTextChange}
fullWidth={true}
inputRef={el => (this.searchField = el)}
placeholder={options.searchPlaceholder}
/>
<IconButton className={classes.clearIcon} onClick={onHide}>
<ClearIcon />
Expand Down
13 changes: 13 additions & 0 deletions test/MUIDataTableSearch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ describe('<TableSearch />', function() {
assert.strictEqual(actualResult.find(TextField).props().value, 'nextText');
});

it('should render a search bar with placeholder when searchPlaceholder is set', () => {
const options = { textLabels, searchPlaceholder: 'TestingPlaceholder' };
const onSearch = () => {};
const onHide = () => {};

const mountWrapper = mount(
<TableSearch onSearch={onSearch} onHide={onHide} options={options} />,
);
const actualResult = mountWrapper.find(TextField);
assert.strictEqual(actualResult.length, 1);
assert.strictEqual(actualResult.props().placeholder, 'TestingPlaceholder');
});

it('should trigger handleTextChange prop callback when calling method handleTextChange', () => {
const options = { onSearchChange: () => true, textLabels };
const onSearch = spy();
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const webpack = require('webpack');

module.exports = {
entry: {
app: "./examples/customize-filter/index.js"
app: "./examples/customize-search/index.js"
},
stats: "verbose",
context: __dirname,
Expand Down