gregnb / mui-datatables

Datatables for React using Material-UI
MIT License
2.71k stars 931 forks source link

Searchbox can be closed and disappears despite searchOpen: true #1344

Open mxmlnglt opened 4 years ago

mxmlnglt commented 4 years ago

Following this showcase: https://codesandbox.io/s/muidatatables-misc-requests-4vkxk

When you set both:

      search: false,
      searchOpen: true,

The searchbox is open (always, as it seems...) and the search icon is disabled: this is to meet our user's requirement i.e. always have a search box.

However:

wdh2100 commented 4 years ago

Thanks for report

      search: false,
      searchOpen: true,

The two conditions seem to contradict.

As you can see, it can cause bugs. We need to change the priority of the two conditions.

mxmlnglt commented 4 years ago

I added a link to https://github.com/gregnb/mui-datatables/issues/1203 for the 2nd bullet point.

patorjk commented 4 years ago

searchOpen should have probably been named searchInitiallyOpen, but I don't want to mess with the name.

In the current setup, an always open search can be accomplished by overiding the Toolbar component via a custom toolbar component. However, this use case seems useful enough that there should probably be an easier solution. I see two options:

For the second option, customToolbar would get access to Toolbar's inner workings, similar to the customSearchRender function. Then making a custom search that's always open could be done the same way customSearchRender is done, ex:

customToolbar: (toolbarMeta) => {
    return (
        <CustomSearchComponent
            searchText={toolbarMeta.searchText}
            onSearch={toolbarMeta.handleSearch}
            options={toolbarMeta.options} />
    );
}

The search would be rendered on the right of the toolbar and never interfear with the title (side note: dispite its name, customToolbar simply adds stuff on the right side of the toolbar). I'm leaning towards the second option. In fact, if a disableClose option was added to TableSearch, one could possibly just plug that component into customToolbar.

Or it could make sense to do both, I'm not sure.