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
10 changes: 8 additions & 2 deletions src/Header/HeaderRow.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { clsx } from 'clsx';
import * as React from 'react';
import Cell from '../Cell';
import TableContext from '../context/TableContext';
Expand Down Expand Up @@ -49,12 +50,17 @@ const HeaderRow = <RecordType extends any>(props: RowProps<RecordType>) => {
const columnsKey = getColumnsKey(cells.map(cell => cell.column));

return (
<RowComponent {...rowProps} className={classNames.row} style={styles.row}>
<RowComponent
{...rowProps}
className={clsx(rowProps?.className, classNames.row) || undefined}
style={{ ...rowProps?.style, ...styles.row }}
>
{cells.map((cell: CellType<RecordType>, cellIndex) => {
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
Expand Down
23 changes: 23 additions & 0 deletions tests/Table.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,29 @@ describe('Table.Basic', () => {
);
});

it('keeps className and style from onHeaderRow', () => {
const onHeaderRow = () => ({ className: 'my-header-row', style: { color: 'red' } });
const { container } = render(createTable({ onHeaderRow }));
const headerRow = container.querySelector('thead tr');
expect(headerRow).toHaveClass('my-header-row');
expect(headerRow.style.color).toBe('red');
});

it('merges onHeaderRow className and style with semantic header row', () => {
const onHeaderRow = () => ({ className: 'my-header-row', style: { color: 'red' } });
const { container } = render(
createTable({
onHeaderRow,
classNames: { header: { row: 'semantic-header-row' } },
styles: { header: { row: { background: 'blue' } } },
}),
);
const headerRow = container.querySelector('thead tr');
expect(headerRow).toHaveClass('my-header-row', 'semantic-header-row');
expect(headerRow.style.color).toBe('red');
expect(headerRow.style.background).toBe('blue');
});

it('renders column.onHeaderCell', () => {
const onHeaderCell = column => ({
id: `header-cell-${column.key}`,
Expand Down