Skip to content

Commit

Permalink
fix: Table empty filters throw warning (#26001)
Browse files Browse the repository at this point in the history
close #25979
  • Loading branch information
afc163 committed Aug 4, 2020
1 parent c4418d0 commit 8d7cbbd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
23 changes: 15 additions & 8 deletions components/table/__tests__/Table.filter.test.js
Expand Up @@ -82,16 +82,23 @@ describe('Table.filter', () => {
});

it('renders empty menu correctly', () => {
const wrapper = mount(createTable({
columns: [
{
...column,
filters: [],
},
],
}));
jest.spyOn(console, 'error').mockImplementation(() => undefined);
const wrapper = mount(
createTable({
columns: [
{
...column,
filters: [],
},
],
}),
);
wrapper.find('span.ant-dropdown-trigger').simulate('click', nativeEvent);
expect(wrapper.find('Empty').length).toBe(1);
// eslint-disable-next-line no-console
expect(console.error).not.toHaveBeenCalled();
// eslint-disable-next-line no-console
console.error.mockRestore();
});

it('renders radio filter correctly', () => {
Expand Down
24 changes: 14 additions & 10 deletions components/table/hooks/useFilter/FilterDropdown.tsx
Expand Up @@ -34,17 +34,21 @@ function renderFilterItems({
locale: TableLocale;
}) {
if (filters.length === 0) {
// wrapped with <></> to avoid react warning
// https://github.com/ant-design/ant-design/issues/25979
return (
<Empty
image={Empty.PRESENTED_IMAGE_SIMPLE}
description={locale.filterEmptyText}
style={{
margin: '16px 0',
}}
imageStyle={{
height: 24,
}}
/>
<>
<Empty
image={Empty.PRESENTED_IMAGE_SIMPLE}
description={locale.filterEmptyText}
style={{
margin: '16px 0',
}}
imageStyle={{
height: 24,
}}
/>
</>
);
}
return filters.map((filter, index) => {
Expand Down

0 comments on commit 8d7cbbd

Please sign in to comment.