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: virtual table should be able to scroll when empty #1135

Merged
merged 8 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/Body/ExpandedRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ function ExpandedRow(props: ExpandedRowProps) {
isEmpty,
} = props;

const { scrollbarSize, fixHeader, fixColumn, componentWidth, horizonScroll } = useContext(
TableContext,
['scrollbarSize', 'fixHeader', 'fixColumn', 'componentWidth', 'horizonScroll'],
);
const { fixColumn, componentWidth, horizonScroll } = useContext(TableContext, [
'scrollbarSize',
'fixHeader',
'fixColumn',
'componentWidth',
'horizonScroll',
]);

// Cache render node
let contentNode = children;
Expand All @@ -44,7 +47,7 @@ function ExpandedRow(props: ExpandedRowProps) {
contentNode = (
<div
style={{
width: componentWidth - (fixHeader ? scrollbarSize : 0),
linxianxi marked this conversation as resolved.
Show resolved Hide resolved
width: componentWidth,
position: 'sticky',
left: 0,
overflow: 'hidden',
Expand Down
2 changes: 1 addition & 1 deletion src/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ function Table<RecordType extends DefaultRecordType>(

if (fixHeader) {
scrollYStyle = {
overflowY: 'scroll',
overflowY: hasData ? 'scroll' : 'auto',
maxHeight: scroll.y,
};
}
Expand Down
14 changes: 0 additions & 14 deletions src/VirtualTable/BodyGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { useContext } from '@rc-component/context';
import classNames from 'classnames';
import VirtualList, { type ListProps, type ListRef } from 'rc-virtual-list';
import * as React from 'react';
import Cell from '../Cell';
import TableContext, { responseImmutable } from '../context/TableContext';
import useFlattenRecords, { type FlattenData } from '../hooks/useFlattenRecords';
import type { ColumnType, OnCustomizeScroll, ScrollConfig } from '../interface';
Expand All @@ -29,7 +27,6 @@ const Grid = React.forwardRef<GridRef, GridProps>((props, ref) => {
expandedKeys,
prefixCls,
childrenColumnName,
emptyNode,
scrollX,
} = useContext(TableContext, [
'flattenColumns',
Expand All @@ -38,7 +35,6 @@ const Grid = React.forwardRef<GridRef, GridProps>((props, ref) => {
'prefixCls',
'expandedKeys',
'childrenColumnName',
'emptyNode',
'scrollX',
]);
const {
Expand Down Expand Up @@ -206,8 +202,6 @@ const Grid = React.forwardRef<GridRef, GridProps>((props, ref) => {

// default 'div' in rc-virtual-list
const wrapperComponent = getComponent(['body', 'wrapper']);
const RowComponent = getComponent(['body', 'row'], 'div');
const cellComponent = getComponent(['body', 'cell'], 'div');

let bodyContent: React.ReactNode;
if (flattenData.length) {
Expand Down Expand Up @@ -248,14 +242,6 @@ const Grid = React.forwardRef<GridRef, GridProps>((props, ref) => {
}}
</VirtualList>
);
} else {
bodyContent = (
linxianxi marked this conversation as resolved.
Show resolved Hide resolved
<RowComponent className={classNames(`${prefixCls}-placeholder`)}>
<Cell component={cellComponent} prefixCls={prefixCls}>
{emptyNode}
</Cell>
</RowComponent>
);
}

return <GridContext.Provider value={gridContext}>{bodyContent}</GridContext.Provider>;
Expand Down
4 changes: 3 additions & 1 deletion src/VirtualTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface VirtualTableProps<RecordType> extends Omit<TableProps<RecordTyp

function VirtualTable<RecordType>(props: VirtualTableProps<RecordType>, ref: React.Ref<Reference>) {
const {
data,
columns,
scroll,
sticky,
Expand Down Expand Up @@ -81,7 +82,8 @@ function VirtualTable<RecordType>(props: VirtualTableProps<RecordType>, ref: Rea
}}
components={{
...components,
body: renderBody,
// fix https://github.com/ant-design/ant-design/issues/48991
body: data?.length ? renderBody : undefined,
}}
columns={columns}
internalHooks={INTERNAL_HOOKS}
Expand Down
Loading