mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-09 10:41:03 +08:00
feat: support ref for Table (#32136)
* feat: support ref/prefix/suffix for Table close #25306 * docs: documentat Table prefix/suffix props * chore: fix lint error * refactor: remove prefix/suffix props
This commit is contained in:
parent
61c21a07f7
commit
15d55bc3e9
@ -99,7 +99,10 @@ export interface TableProps<RecordType>
|
|||||||
showSorterTooltip?: boolean | TooltipProps;
|
showSorterTooltip?: boolean | TooltipProps;
|
||||||
}
|
}
|
||||||
|
|
||||||
function Table<RecordType extends object = any>(props: TableProps<RecordType>) {
|
function InternalTable<RecordType extends object = any>(
|
||||||
|
props: TableProps<RecordType>,
|
||||||
|
ref: React.MutableRefObject<HTMLDivElement>,
|
||||||
|
) {
|
||||||
const {
|
const {
|
||||||
prefixCls: customizePrefixCls,
|
prefixCls: customizePrefixCls,
|
||||||
className,
|
className,
|
||||||
@ -483,7 +486,7 @@ function Table<RecordType extends object = any>(props: TableProps<RecordType>) {
|
|||||||
className,
|
className,
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<div className={wrapperClassNames} style={style}>
|
<div ref={ref} className={wrapperClassNames} style={style}>
|
||||||
<Spin spinning={false} {...spinProps}>
|
<Spin spinning={false} {...spinProps}>
|
||||||
{topPaginationNode}
|
{topPaginationNode}
|
||||||
<RcTable<RecordType>
|
<RcTable<RecordType>
|
||||||
@ -513,6 +516,21 @@ function Table<RecordType extends object = any>(props: TableProps<RecordType>) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const TableRef = React.forwardRef(InternalTable);
|
||||||
|
|
||||||
|
type InternalTableType = typeof TableRef;
|
||||||
|
|
||||||
|
interface TableInterface extends InternalTableType {
|
||||||
|
SELECTION_ALL: 'SELECT_ALL';
|
||||||
|
SELECTION_INVERT: 'SELECT_INVERT';
|
||||||
|
SELECTION_NONE: 'SELECT_NONE';
|
||||||
|
Column: typeof Column;
|
||||||
|
ColumnGroup: typeof ColumnGroup;
|
||||||
|
Summary: typeof Summary;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Table = TableRef as TableInterface;
|
||||||
|
|
||||||
Table.defaultProps = {
|
Table.defaultProps = {
|
||||||
rowKey: 'key',
|
rowKey: 'key',
|
||||||
};
|
};
|
||||||
|
@ -261,4 +261,21 @@ describe('Table', () => {
|
|||||||
mount(<Table columns={columns} rowKey={record => record.key} />);
|
mount(<Table columns={columns} rowKey={record => record.key} />);
|
||||||
expect(warnSpy).not.toBeCalled();
|
expect(warnSpy).not.toBeCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should support ref', () => {
|
||||||
|
warnSpy.mockReset();
|
||||||
|
const columns = [
|
||||||
|
{
|
||||||
|
title: 'Name',
|
||||||
|
key: 'name',
|
||||||
|
dataIndex: 'name',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const Wrapper = () => {
|
||||||
|
const ref = React.useRef();
|
||||||
|
return <Table ref={ref} columns={columns} />;
|
||||||
|
};
|
||||||
|
mount(<Wrapper />);
|
||||||
|
expect(warnSpy).not.toBeCalled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user