Skip to content

Commit

Permalink
fix(TableExpandHeader): add default id value (#12262)
Browse files Browse the repository at this point in the history
* fix: add default headers and id value to expand dt

* chore: update snapshots

Co-authored-by: Alessandra Davila <adavila91@gmail.com>
  • Loading branch information
jnm2377 and aledavila authored Oct 11, 2022
1 parent 79b7a1a commit 607e05b
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 18 deletions.
12 changes: 6 additions & 6 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1688,6 +1688,9 @@ Map {
"expandIconDescription": Object {
"type": "string",
},
"id": Object {
"type": "string",
},
"isExpanded": [Function],
"onExpand": Object {
"args": Array [
Expand All @@ -1701,9 +1704,6 @@ Map {
},
},
"TableExpandRow": Object {
"defaultProps": Object {
"expandHeader": "expand",
},
"propTypes": Object {
"ariaLabel": Object {
"isRequired": true,
Expand Down Expand Up @@ -6960,6 +6960,9 @@ Map {
"expandIconDescription": Object {
"type": "string",
},
"id": Object {
"type": "string",
},
"isExpanded": [Function],
"onExpand": Object {
"args": Array [
Expand All @@ -6973,9 +6976,6 @@ Map {
},
},
"TableExpandRow" => Object {
"defaultProps": Object {
"expandHeader": "expand",
},
"propTypes": Object {
"ariaLabel": Object {
"isRequired": true,
Expand Down
7 changes: 7 additions & 0 deletions packages/react/src/components/DataTable/TableExpandHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const TableExpandHeader = ({
className: headerClassName,
enableExpando,
enableToggle,
id = 'expand',
isExpanded,
onExpand,
expandIconDescription,
Expand All @@ -33,6 +34,7 @@ const TableExpandHeader = ({
scope="col"
className={className}
data-previous-value={previousValue}
id={id}
{...rest}>
{enableExpando || enableToggle ? (
<button
Expand Down Expand Up @@ -84,6 +86,11 @@ TableExpandHeader.propTypes = {
*/
expandIconDescription: PropTypes.string,

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

/**
* Specify whether this row is expanded or not. This helps coordinate data
* attributes so that `TableExpandRow` and `TableExpandedRow` work together
Expand Down
6 changes: 1 addition & 5 deletions packages/react/src/components/DataTable/TableExpandRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const TableExpandRow = ({
onExpand,
expandIconDescription,
isSelected,
expandHeader,
expandHeader = 'expand',
...rest
}) => {
const prefix = usePrefix();
Expand Down Expand Up @@ -92,8 +92,4 @@ TableExpandRow.propTypes = {
onExpand: PropTypes.func.isRequired,
};

TableExpandRow.defaultProps = {
expandHeader: 'expand',
};

export default TableExpandRow;
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ exports[`DataTable.TableExpandHeader should render 1`] = `
>
<th
className="cds--table-expand custom-class"
id="expand"
scope="col"
/>
</TableExpandHeader>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ exports[`DataTable.TableExpandRow should render 1`] = `
<TableExpandRow
ariaLabel="Aria label"
className="custom-class"
expandHeader="expand"
isExpanded={false}
onExpand={[MockFunction]}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const Default = () => (
<Table {...getTableProps()}>
<TableHead>
<TableRow>
<TableExpandHeader id="expand" />
<TableExpandHeader />
{headers.map((header, i) => (
<TableHeader key={i} {...getHeaderProps({ header })}>
{header.header}
Expand All @@ -73,7 +73,7 @@ export const Default = () => (
<TableBody>
{rows.map((row) => (
<React.Fragment key={row.id}>
<TableExpandRow expandHeader="expand" {...getRowProps({ row })}>
<TableExpandRow {...getRowProps({ row })}>
{row.cells.map((cell) => (
<TableCell key={cell.id}>{cell.value}</TableCell>
))}
Expand Down Expand Up @@ -114,7 +114,6 @@ export const BatchExpansion = () => (
<TableHead>
<TableRow>
<TableExpandHeader
id="expand"
enableExpando={true}
{...getExpandHeaderProps()}
/>
Expand All @@ -128,7 +127,7 @@ export const BatchExpansion = () => (
<TableBody>
{rows.map((row) => (
<React.Fragment key={row.id}>
<TableExpandRow expandHeader="expand" {...getRowProps({ row })}>
<TableExpandRow {...getRowProps({ row })}>
{row.cells.map((cell) => (
<TableCell key={cell.id}>{cell.value}</TableCell>
))}
Expand Down Expand Up @@ -278,7 +277,7 @@ export const Playground = (args) => (
<Table {...getTableProps()}>
<TableHead>
<TableRow>
<TableExpandHeader id="expand" />
<TableExpandHeader />
{headers.map((header, i) => (
<TableHeader key={i} {...getHeaderProps({ header })}>
{header.header}
Expand All @@ -289,7 +288,7 @@ export const Playground = (args) => (
<TableBody>
{rows.map((row) => (
<React.Fragment key={row.id}>
<TableExpandRow expandHeader="expand" {...getRowProps({ row })}>
<TableExpandRow {...getRowProps({ row })}>
{row.cells.map((cell) => (
<TableCell key={cell.id}>{cell.value}</TableCell>
))}
Expand Down

0 comments on commit 607e05b

Please sign in to comment.