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

fix: Table empty filters throw warning #26001

Merged
merged 1 commit into from Aug 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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