react-admin icon indicating copy to clipboard operation
react-admin copied to clipboard

Clearing filters using setFilter({}) does not clear FilterLiveSearch text input

Open greatwitenorth opened this issue 10 months ago • 2 comments

What you were expecting: When I call setFilter({}) I expected it to clear out all filters and text inside the FilterLiveSearch input box.

What happened instead: The filters are removed, but the text remains in the FilterLiveSearch input box. The results are not filtering by the text in FilterLiveSearch anymore.

Steps to reproduce:

  • Add a FilterLiveSearch component
  • Add a button to clear the filter
  • Click the button

Related code: AssetFilterSidebar.jsx

  export const AssetFilterSidebar = (props) => {
    const { setFilters } = useListContext();

    const { data: catData, isLoading: catIsLoading } = useGetList('categories', {
      sort: { field: 'name', order: 'ASC' },
    });

    const { data: companyData, isLoading: companyIsLoading } = useGetList('companies', {
      sort: { field: 'name', order: 'ASC' },
    });

    return (
      <Card sx={{ order: -1, mr: 2, mt: 6, width: 300 }}>
        <CardContent>
          <SavedQueriesList/>
          <FilterLiveSearch source="company#name@_ilike,name@_ilike,serial@_ilike" />
          <Button onClick={() => {
            setFilters({});
          }}>Clear filters</Button>
          <FilterList label="Company" icon={<BusinessIcon/>}>
            {!companyIsLoading && companyData.map((company) => (
              <FilterListItem key={company.name} label={company.name} value={{ 'company#name@_eq': company.name }} />
            ))}
          </FilterList>
          <FilterList label="Category" icon={<CategoryIcon/>}>
            {!catIsLoading && catData.map((cat) => (
              <FilterListItem key={cat.name} label={cat.name} value={{ 'category#name@_eq': cat.name }} />
            ))}
          </FilterList>
        </CardContent>
      </Card>
    );
  };
  • Preferably, a sandbox forked from
    • https://stackblitz.com/github/marmelab/react-admin/tree/master/examples/simple (v4) Unfortunately the above url is not currently working (once installed, the screen just shows blank)

Environment

  • React-admin version: 4.16.13
  • Last version that did not exhibit the issue (if applicable): na
  • React version: 18.2.0
  • Browser: chrome 124.0.6367.60
  • Stack trace (in case of a JS error): na

greatwitenorth avatar Apr 23 '24 20:04 greatwitenorth

Hi @greatwitenorth. Stackblitz have some problems sometimes. You can reload it, wait more or open a new tab with the blank page url to force it to load.

I can't reproduce your bug, could you please try to make a reproduction on Stackblitz

erwanMarmelab avatar Apr 29 '24 08:04 erwanMarmelab

Alternatively you can also use codesandbox: https://codesandbox.io/s/github/marmelab/react-admin/tree/master/examples/simple

slax57 avatar May 07 '24 09:05 slax57

No news for some time, closing.

fzaninotto avatar May 20 '24 12:05 fzaninotto