Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions src/Body/MeasureCell.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import ResizeObserver from '@rc-component/resize-observer';
import { useLayoutEffect } from '@rc-component/util';
import { isReactRenderable, useLayoutEffect } from '@rc-component/util';

export interface MeasureCellProps {
columnKey: React.Key;
Expand All @@ -25,7 +25,9 @@ const MeasureCell: React.FC<MeasureCellProps> = props => {
ref={cellRef}
style={{ paddingTop: 0, paddingBottom: 0, borderTop: 0, borderBottom: 0, height: 0 }}
>
<div style={{ height: 0, overflow: 'hidden', fontWeight: 'bold' }}>{title || '\xa0'}</div>
<div style={{ height: 0, overflow: 'hidden', fontWeight: 'bold' }}>
{isReactRenderable(title) ? title : '\xa0'}
</div>
</td>
</ResizeObserver>
);
Expand Down
6 changes: 4 additions & 2 deletions src/Header/HeaderRow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { isReactRenderable } from '@rc-component/util';
import Cell from '../Cell';
import TableContext from '../context/TableContext';
import { useContext } from '@rc-component/context';
Expand Down Expand Up @@ -54,12 +55,13 @@ const HeaderRow = <RecordType extends any>(props: RowProps<RecordType>) => {
const { column, colStart, colEnd, colSpan } = cell;
const fixedInfo = getCellFixedInfo(colStart, colEnd, flattenColumns, stickyOffsets);

const additionalProps: React.HTMLAttributes<HTMLElement> = column?.onHeaderCell?.(column) || {};
const additionalProps: React.HTMLAttributes<HTMLElement> =
column?.onHeaderCell?.(column) || {};

return (
<Cell
{...cell}
scope={column.title ? (colSpan > 1 ? 'colgroup' : 'col') : null}
scope={isReactRenderable(column.title) ? (colSpan > 1 ? 'colgroup' : 'col') : null}
ellipsis={column.ellipsis}
align={column.align}
component={CellComponent}
Expand Down
38 changes: 38 additions & 0 deletions tests/renderability.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react';
import { render } from '@testing-library/react';
import Table from '../src';
import MeasureCell from '../src/Body/MeasureCell';

it('sets the scope for zero column and group titles', () => {
const { container } = render(
<Table
columns={[
{
title: 0,
children: [
{ title: 0, dataIndex: 'a' },
{ title: 'B', dataIndex: 'b' },
],
},
]}
data={[]}
/>,
);
const headers = container.querySelectorAll('th');
expect(headers[0]).toHaveAttribute('scope', 'colgroup');
expect(headers[1]).toHaveAttribute('scope', 'col');
expect(headers[1].textContent).toBe('0');
});

it('measures the zero title rather than a blank fallback', () => {
const { container } = render(
<table>
<tbody>
<tr>
<MeasureCell title={0} columnKey="a" onColumnResize={() => {}} />
</tr>
</tbody>
</table>,
);
expect(container.querySelector('td').textContent).toBe('0');
});
Loading