diff --git a/src/Header/HeaderRow.tsx b/src/Header/HeaderRow.tsx index 9a84c7ba2..6140c8cdc 100644 --- a/src/Header/HeaderRow.tsx +++ b/src/Header/HeaderRow.tsx @@ -1,3 +1,4 @@ +import { clsx } from 'clsx'; import * as React from 'react'; import Cell from '../Cell'; import TableContext from '../context/TableContext'; @@ -49,12 +50,17 @@ const HeaderRow = (props: RowProps) => { const columnsKey = getColumnsKey(cells.map(cell => cell.column)); return ( - + {cells.map((cell: CellType, cellIndex) => { const { column, colStart, colEnd, colSpan } = cell; const fixedInfo = getCellFixedInfo(colStart, colEnd, flattenColumns, stickyOffsets); - const additionalProps: React.HTMLAttributes = column?.onHeaderCell?.(column) || {}; + const additionalProps: React.HTMLAttributes = + column?.onHeaderCell?.(column) || {}; return ( { ); }); + 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}`,