Skip to content

Commit

Permalink
Restore support for styling a TableHeader (#2226)
Browse files Browse the repository at this point in the history
  • Loading branch information
connor-baer authored Aug 24, 2023
1 parent 3deeb5c commit 6eb8a5f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/unlucky-pumas-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sumup/circuit-ui': patch
---

Fixed forwarding a custom `className` to the TableHeader component.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import { TdHTMLAttributes, forwardRef } from 'react';

import { clsx } from '../../../../styles/clsx.js';
import type { CellAlignment } from '../../types.js';

import classes from './TableCell.module.css';

Expand All @@ -25,7 +26,7 @@ export interface TableCellProps extends TdHTMLAttributes<HTMLTableCellElement> {
/**
* Aligns the content of the Cell with text-align.
*/
align?: 'left' | 'right' | 'center';
align?: CellAlignment;
/**
* Adds heading styles to placeholder Cell.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ import TableHeader from './index.js';
const children = 'Foo';

describe('TableHeader', () => {
it('should merge a custom class name with the default ones', () => {
const className = 'foo';
const { container } = render(
<TableHeader
sortParams={{
sortable: true,
sortLabel: 'Sort in ascending order',
isSorted: false,
}}
className={className}
>
{children}
</TableHeader>,
);
const tableHeader = container.querySelector('th');
expect(tableHeader?.className).toContain(className);
});

it('should have no accessibility violations', async () => {
const { container } = render(
<TableHeader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export function TableHeader({
fixed = false,
isHovered = false,
sortParams = { sortable: false },
className,
onClick,
...props
}: TableHeaderProps) {
Expand All @@ -90,6 +91,7 @@ export function TableHeader({
isHovered && classes.hover,
fixed && classes.fixed,
condensed && classes.condensed,
className,
)}
scope={scope}
aria-label={sortParams.sortLabel}
Expand Down
1 change: 1 addition & 0 deletions packages/circuit-ui/components/Table/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type SortableRowCell = {
type CellObject = {
'children': ReactNode;
'align'?: CellAlignment;
'className'?: string;
'data-testid'?: string;
};

Expand Down

1 comment on commit 6eb8a5f

@vercel
Copy link

@vercel vercel bot commented on 6eb8a5f Aug 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.