Skip to content

Allow Class Specification on TableColumn #637

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

Open
wants to merge 3 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@launchpadlab/lp-components",
"version": "10.0.1",
"version": "10.1.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we have to qualify this as a breaking change and add some notes to a migration guide.

Any styles that are only applied to a class passed in to a column will be applied to headers as well. In the notes, we should add that if the user does not wish for these styles to apply, then they must include a more specific selector that includes the element, e.g., td.foo {} instead of just .foo {}

"engines": {
"node": "^18.12 || ^20.0"
},
Expand Down
4 changes: 2 additions & 2 deletions src/tables/components/table-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const propTypes = {
}

function TableHeader({
column: { name, label, disabled },
column: { className, name, label, disabled },
sortPath,
ascending,
onClick,
Expand All @@ -22,7 +22,7 @@ function TableHeader({
return (
<th
onClick={onClick}
className={classnames(arrowClass, { sortable: !disabled })}
className={classnames(arrowClass, { sortable: !disabled }, className)}
>
{label || startCase(name)}
</th>
Expand Down
11 changes: 11 additions & 0 deletions test/tables/sortable-table.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,4 +476,15 @@ describe('SortableTable', () => {
)
expect(screen.getByText('My Table')).toHaveClass('custom-caption')
})

test('Column with custom className is propagated to TableHeader', () => {
render(
<SortableTable data={tableData}>
<Column name="name" className="foo" />
</SortableTable>
)

const header = screen.getByText('Name').closest('th')
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need closest here? When I printed out the value for screen.getByText('Name'), it was the header itself 🤔

expect(header).toHaveClass('foo')
})
})