Skip to content

Commit

Permalink
fix: getPopupContainer not work inject by ConfigProvider (ant-design#…
Browse files Browse the repository at this point in the history
…40781) (ant-design#40871)

* fix: getPopupContainer not work inject by ConfigProvider (ant-design#40781)

* test: remove snapshot

* test: fix snapshots
  • Loading branch information
RedJue committed Apr 25, 2023
1 parent 8c1d0b0 commit c01940b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
11 changes: 6 additions & 5 deletions components/table/InternalTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ import type { SortState } from './hooks/useSorter';
import useSorter, { getSortData } from './hooks/useSorter';
import useTitleColumns from './hooks/useTitleColumns';
import type {
ColumnsType,
ColumnTitleProps,
ColumnType,
ExpandableConfig,
ExpandType,
FilterValue,
GetPopupContainer,
GetRowKey,
RefInternalTable,
SorterResult,
SortOrder,
TableAction,
TableCurrentDataSource,
TableLocale,
TableRowSelection,
ColumnsType,
TablePaginationConfig,
RefInternalTable,
TableRowSelection,
} from './interface';
import RcTable from './RcTable';

Expand Down Expand Up @@ -114,6 +114,7 @@ function InternalTable<RecordType extends object = any>(
props: InternalTableProps<RecordType>,
ref: React.MutableRefObject<HTMLDivElement>,
) {
const { getPopupContainer: getContextPopupContainer } = React.useContext(ConfigContext);
const {
prefixCls: customizePrefixCls,
className,
Expand Down Expand Up @@ -323,7 +324,7 @@ function InternalTable<RecordType extends object = any>(
dropdownPrefixCls,
mergedColumns,
onFilterChange,
getPopupContainer,
getPopupContainer: getPopupContainer || getContextPopupContainer,
});
const mergedData = getFilterData(sortedData, filterStates);

Expand Down Expand Up @@ -408,7 +409,7 @@ function InternalTable<RecordType extends object = any>(
expandType,
childrenColumnName,
locale: tableLocale,
getPopupContainer,
getPopupContainer: getPopupContainer || getContextPopupContainer,
});

const internalRowClassName = (record: RecordType, index: number, indent: number) => {
Expand Down
34 changes: 33 additions & 1 deletion components/table/__tests__/Table.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ConfigProvider } from 'antd';
import React from 'react';
import React, { useRef } from 'react';
import type { TableProps } from '..';
import Table from '..';
import mountTest from '../../../tests/shared/mountTest';
Expand Down Expand Up @@ -369,4 +369,36 @@ describe('Table', () => {
);
expect(container.firstChild).toMatchSnapshot();
});

it('support getPopupContainer inject by ConfigProvider', async () => {
const columns = [
{
title: 'title',
key: 'title',
dataIndex: 'title',
filters: [
{
text: 'filter',
value: 'filter',
},
],
},
];
const Demo = () => {
const wrapRef = useRef(null);
return (
<ConfigProvider getPopupContainer={wrapRef.current!}>
<div ref={wrapRef}>
<Table columns={columns} />
</div>
</ConfigProvider>
);
};

const { container } = render(<Demo />);

fireEvent.click(container.querySelector('.ant-table-filter-trigger')!);
await waitFakeTimer();
expect(container.querySelector('.ant-dropdown')).toBeTruthy();
});
});

0 comments on commit c01940b

Please sign in to comment.