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
|**`showSearch`**|boolean|false|Initially displays search bar
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about calling the option searchOpen instead? My concern is that I want to distinguish it from the numerous search options that exist now, and I worry it may cause confusion with the option that shows/hides the icon form the 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
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.showSearch),
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.showSearch = true', () => {
const newOptions = { ...options, showSearch: 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