chore: fix Table filter behavior when filterDropdown is undefined (#53421)

This commit is contained in:
afc163 2025-04-08 19:02:51 +08:00 committed by GitHub
parent 529f539a0f
commit 7688c20bdc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 2 deletions

View File

@ -193,6 +193,30 @@ describe('Table.filter', () => {
);
});
// https://github.com/ant-design/ant-design/issues/49025
it('should handle filterDropdown undefined correctly', () => {
const { container } = render(
createTable({
columns: [
{
...column,
filters: [
{ text: 'Boy', value: true },
{ text: 'Girl', value: false },
],
filteredValue: [true],
filterDropdown: undefined,
},
],
}),
);
// 首先点击打开筛选菜单
fireEvent.click(container.querySelector('.ant-table-filter-trigger')!);
// 检查是否正确选中了Boy选项
const boyMenuItem = container.querySelectorAll('.ant-dropdown-menu-item-selected')[0];
expect(boyMenuItem.textContent).toBe('Boy');
});
it('override custom filter correctly', () => {
let renderSelectedKeys: React.Key[] | null = null;
const filter = ({

View File

@ -33,12 +33,13 @@ const collectFilterStates = <RecordType extends AnyObject = AnyObject>(
(columns || []).forEach((column, index) => {
const columnPos = getColumnPos(index, pos);
const filterDropdownIsDefined = column.filterDropdown !== undefined;
if (column.filters || 'filterDropdown' in column || 'onFilter' in column) {
if (column.filters || filterDropdownIsDefined || 'onFilter' in column) {
if ('filteredValue' in column) {
// Controlled
let filteredValues = column.filteredValue;
if (!('filterDropdown' in column)) {
if (!filterDropdownIsDefined) {
filteredValues = filteredValues?.map(String) ?? filteredValues;
}
filterStates.push({