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

Feature/Allow to display search bar from init #893

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,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 @@ -165,6 +165,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