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
headerId={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 headerId={header.key} key={header}>
{header}
</TableHeader>
))}
</TableRow>
</TableHead>
Expand Down Expand Up @@ -397,7 +400,10 @@ export const Playground = () => (
<TableHead>
<TableRow>
{headers.map((header, i) => (
<TableHeader key={i} {...getHeaderProps({ header })}>
<TableHeader
headerId={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,
headerId,
...rest
},
ref
Expand All @@ -72,6 +73,7 @@ const TableHeader = React.forwardRef(function TableHeader(
return (
<th
{...rest}
id={headerId}
className={headerClassName}
scope={scope}
colSpan={colSpan}
Expand Down Expand Up @@ -100,6 +102,7 @@ const TableHeader = React.forwardRef(function TableHeader(

return (
<th
id={headerId}
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.
*/
headerId: PropTypes.string,
tay1orjones marked this conversation as resolved.
Show resolved Hide resolved

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