Skip to content

Commit

Permalink
fix: Table should not crash if filterDropdown is boolean (ant-design#…
Browse files Browse the repository at this point in the history
…44357)

* fix: Table should not crash if filterDropdown is boolean

* chore: code clean

* chore: use supportNodeRef
  • Loading branch information
MadCcc authored Aug 23, 2023
1 parent 5d522a3 commit 79825c0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
7 changes: 6 additions & 1 deletion components/menu/OverrideContext.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import { NoCompactStyle } from '../space/Compact';
import type { MenuProps } from './menu';
import { supportNodeRef } from 'rc-util';

// Used for Dropdown only
export interface OverrideContextProps {
Expand Down Expand Up @@ -36,7 +37,11 @@ export const OverrideProvider = React.forwardRef<

return (
<OverrideContext.Provider value={context}>
<NoCompactStyle>{React.cloneElement(children as React.ReactElement, { ref })}</NoCompactStyle>
<NoCompactStyle>
{supportNodeRef(children)
? React.cloneElement(children as React.ReactElement, { ref })
: children}
</NoCompactStyle>
</OverrideContext.Provider>
);
});
Expand Down
20 changes: 20 additions & 0 deletions components/table/__tests__/Table.filter.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2834,4 +2834,24 @@ describe('Table.filter', () => {
true,
);
});

it('should not crash when filterDropdown is boolean', () => {
const tableProps = {
key: 'stabletable',
rowKey: 'name',
dataSource: [],
columns: [
{
title: 'Name',
dataIndex: 'name',
filterDropdown: true,
},
],
};

const { container } = render(createTable(tableProps));

// User opens filter Dropdown.
fireEvent.click(container.querySelector('.ant-dropdown-trigger.ant-table-filter-trigger')!);
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
"rc-tree": "~5.7.6",
"rc-tree-select": "~5.11.0",
"rc-upload": "~4.3.0",
"rc-util": "^5.32.0",
"rc-util": "^5.37.0",
"scroll-into-view-if-needed": "^3.0.3",
"throttle-debounce": "^5.0.0"
},
Expand Down

0 comments on commit 79825c0

Please sign in to comment.