Skip to content

Commit

Permalink
Feature/Allow to display search bar from init (gregnb#893)
Browse files Browse the repository at this point in the history
* Add option to display search bar at init

* rename showSearch to searchOpen. add propType.

* Revert "rename showSearch to searchOpen. add propType."

* fixed: searchOpen with propType
  • Loading branch information
RafaelloLollipop authored and waqasajaz committed Oct 31, 2019
1 parent 67331ee commit d088a69
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ The component accepts the following props:
|**`sort`**|boolean|true|Enable/disable sort on all columns
|**`filter`**|boolean|true|Show/hide filter icon from toolbar
|**`search`**|boolean|true|Show/hide search icon from toolbar
|**`searchOpen`**|boolean|false|Initially displays search bar
|**`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
Expand Down
1 change: 1 addition & 0 deletions src/MUIDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class MUIDataTable extends React.Component {
customSort: PropTypes.func,
customSearch: PropTypes.func,
search: PropTypes.bool,
searchOpen: PropTypes.bool,
searchText: PropTypes.string,
searchPlaceholder: PropTypes.string,
print: PropTypes.bool,
Expand Down
2 changes: 1 addition & 1 deletion src/components/TableToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const defaultToolbarStyles = theme => ({
class TableToolbar extends React.Component {
state = {
iconActive: null,
showSearch: Boolean(this.props.searchText || this.props.options.searchText),
showSearch: Boolean(this.props.searchText || this.props.options.searchText || this.props.options.searchOpen),
searchText: this.props.searchText || null,
};

Expand Down
10 changes: 10 additions & 0 deletions test/MUIDataTableToolbar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ describe('<TableToolbar />', function() {
assert.strictEqual(actualResult.props().options.searchText, 'searchText');
});

it('should render a toolbar with search if option.searchOpen = true', () => {
const newOptions = { ...options, searchOpen: true };
const mountWrapper = mount(
<TableToolbar columns={columns} data={data} options={newOptions} setTableAction={setTableAction} />,
);
const actualResult = mountWrapper.find(TableSearch);
assert.strictEqual(actualResult.length, 1);
assert.strictEqual(actualResult.props().options.searchText, undefined);
});

it('should render a toolbar with no search icon if option.search = false', () => {
const newOptions = { ...options, search: false };
const mountWrapper = mount(
Expand Down

0 comments on commit d088a69

Please sign in to comment.