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

Added support for headerRowClass. #3405

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@

npm-debug.log
**.orig
.idea
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ function MyGrid() {

###### `rowClass?: Maybe<(row: R) => Maybe<string>>`

###### `headerRowClass?: Maybe<string>>`

##### `direction?: Maybe<'ltr' | 'rtl'>`

This property sets the text direction of the grid, it defaults to `'ltr'` (left-to-right). Setting `direction` to `'rtl'` has the following effects:
Expand Down
3 changes: 3 additions & 0 deletions src/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export interface DataGridProps<R, SR = unknown, K extends Key = Key> extends Sha
*/
renderers?: Maybe<Renderers<R, SR>>;
rowClass?: Maybe<(row: R, rowIdx: number) => Maybe<string>>;
headerRowClass?: Maybe<string>;
/** @default 'ltr' */
direction?: Maybe<Direction>;
'data-testid'?: Maybe<string>;
Expand Down Expand Up @@ -240,6 +241,7 @@ function DataGrid<R, SR, K extends Key>(
className,
style,
rowClass,
headerRowClass,
direction: rawDirection,
// ARIA
role: rawRole,
Expand Down Expand Up @@ -1092,6 +1094,7 @@ function DataGrid<R, SR, K extends Key>(
/>
))}
<HeaderRow
headerRowClass={headerRowClass}
rowIdx={headerRowsCount}
columns={getRowViewportColumns(mainHeaderRowIdx)}
onColumnResize={handleColumnResizeLatest}
Expand Down
15 changes: 11 additions & 4 deletions src/HeaderRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import clsx from 'clsx';

import { getColSpan } from './utils';
import type { CalculatedColumn, Direction, Position } from './types';
import { Maybe } from './types';
import type { DataGridProps } from './DataGrid';
import HeaderCell from './HeaderCell';
import { cell, cellFrozen } from './style/cell';
Expand All @@ -23,10 +24,11 @@ export interface HeaderRowProps<R, SR, K extends React.Key> extends SharedDataGr
selectedCellIdx: number | undefined;
shouldFocusGrid: boolean;
direction: Direction;
headerRowClass: Maybe<string>;
}

const headerRow = css`
@layer rdg.HeaderRow {
@layer rdg . HeaderRow {
display: contents;
line-height: var(--rdg-header-row-height);
background-color: var(--rdg-header-background-color);
Expand All @@ -47,6 +49,7 @@ const headerRow = css`
export const headerRowClassname = `rdg-header-row ${headerRow}`;

function HeaderRow<R, SR, K extends React.Key>({
headerRowClass,
rowIdx,
columns,
onColumnResize,
Expand Down Expand Up @@ -92,9 +95,13 @@ function HeaderRow<R, SR, K extends React.Key>({
<div
role="row"
aria-rowindex={rowIdx} // aria-rowindex is 1 based
className={clsx(headerRowClassname, {
[rowSelectedClassname]: selectedCellIdx === -1
})}
className={clsx(
headerRowClassname,
{
[rowSelectedClassname]: selectedCellIdx === -1
},
headerRowClass
)}
>
{cells}
</div>
Expand Down