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

feat(TableHeader): add id prop #10214

Merged
10 changes: 8 additions & 2 deletions packages/react/src/components/DataTable/DataTable-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export const Usage = () => (
<TableRow>
{headers.map((header) => (
<TableHeader
id={header.key}
key={header.key}
{...getHeaderProps({ header })}
isSortable>
Expand Down Expand Up @@ -139,7 +140,9 @@ export const BasicTable = () => {
<TableHead>
<TableRow>
{headers.map((header) => (
<TableHeader key={header}>{header}</TableHeader>
<TableHeader id={header.key} key={header}>
{header}
</TableHeader>
))}
</TableRow>
</TableHead>
Expand Down Expand Up @@ -408,7 +411,10 @@ export const Playground = () => (
<TableHead>
<TableRow>
{headers.map((header, i) => (
<TableHeader key={i} {...getHeaderProps({ header })}>
<TableHeader
id={header.key}
key={i}
{...getHeaderProps({ header })}>
{header.header}
</TableHeader>
))}
Expand Down
8 changes: 8 additions & 0 deletions packages/react/src/components/DataTable/TableHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const TableHeader = React.forwardRef(function TableHeader(
scope,
sortDirection,
translateWithId: t,
id,
...rest
},
ref
Expand All @@ -72,6 +73,7 @@ const TableHeader = React.forwardRef(function TableHeader(
return (
<th
{...rest}
id={id}
className={headerClassName}
scope={scope}
colSpan={colSpan}
Expand Down Expand Up @@ -100,6 +102,7 @@ const TableHeader = React.forwardRef(function TableHeader(

return (
<th
id={id}
aria-sort={ariaSort}
className={headerClassName}
colSpan={colSpan}
Expand Down Expand Up @@ -141,6 +144,11 @@ TableHeader.propTypes = {
*/
colSpan: PropTypes.number,

/**
* Supply an id to the th element.
*/
id: PropTypes.string,

/**
* Specify whether this header is the header by which a table is being sorted
* by
Expand Down