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(TableContainer): support id-ref for the header #4807

Closed
wants to merge 9 commits into from
12 changes: 12 additions & 0 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -871,9 +871,15 @@ Map {
"description": Object {
"type": "node",
},
"descriptionId": Object {
"type": "string",
},
"title": Object {
"type": "node",
},
"titleId": Object {
"type": "string",
},
},
},
"TableExpandHeader": Object {
Expand Down Expand Up @@ -1447,9 +1453,15 @@ Map {
"description": Object {
"type": "node",
},
"descriptionId": Object {
"type": "string",
},
"title": Object {
"type": "node",
},
"titleId": Object {
"type": "string",
},
},
},
"TableExpandHeader" => Object {
Expand Down
4 changes: 4 additions & 0 deletions packages/react/src/components/DataTable/DataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ export default class DataTable extends React.Component {
useStaticWidth,
shouldShowBorder,
stickyHeader,
'aria-labelledby': `${this.getTablePrefix()}__table-container__title`,
'aria-describedby': `${this.getTablePrefix()}__table-container__description`,
};
};

Expand All @@ -383,6 +385,8 @@ export default class DataTable extends React.Component {
const { stickyHeader } = this.props;

return {
titleId: `${this.getTablePrefix()}__table-container__title`,
descriptionId: `${this.getTablePrefix()}__table-container__description`,
stickyHeader,
};
};
Expand Down
20 changes: 18 additions & 2 deletions packages/react/src/components/DataTable/TableContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ const TableContainer = ({
className,
children,
title,
titleId,
description,
descriptionId,
stickyHeader,
...rest
}) => {
Expand All @@ -32,8 +34,12 @@ const TableContainer = ({
<div {...rest} className={tableContainerClasses}>
{title && (
<div className={`${prefix}--data-table-header`}>
<h4 className={`${prefix}--data-table-header__title`}>{title}</h4>
<p className={`${prefix}--data-table-header__description`}>
<h4 id={titleId} className={`${prefix}--data-table-header__title`}>
{title}
</h4>
<p
id={descriptionId}
className={`${prefix}--data-table-header__description`}>
{description}
</p>
</div>
Expand All @@ -51,10 +57,20 @@ TableContainer.propTypes = {
*/
title: PropTypes.node,

/**
* Provide an element ID of the title for the Table
*/
titleId: PropTypes.string,

/**
* Optional description text for the Table
*/
description: PropTypes.node,

/**
* Provide an element ID of the description for the Table
*/
descriptionId: PropTypes.string,
};

export default TableContainer;
Original file line number Diff line number Diff line change
Expand Up @@ -1777,7 +1777,9 @@ exports[`DataTable should render 1`] = `
Object {
"type": "return",
"value": <TableContainer
descriptionId="data-table-1__table-container__description"
title="DataTable with toolbar"
titleId="data-table-1__table-container__title"
>
<TableToolbar
aria-label="data table toolbar"
Expand Down Expand Up @@ -1869,6 +1871,8 @@ exports[`DataTable should render 1`] = `
</TableToolbarContent>
</TableToolbar>
<Table
aria-describedby="data-table-1__table-container__description"
aria-labelledby="data-table-1__table-container__title"
isSortable={false}
size="normal"
>
Expand Down Expand Up @@ -1954,7 +1958,9 @@ exports[`DataTable should render 1`] = `
translateWithId={[Function]}
>
<TableContainer
descriptionId="data-table-1__table-container__description"
title="DataTable with toolbar"
titleId="data-table-1__table-container__title"
>
<div
className="bx--data-table-container"
Expand All @@ -1964,11 +1970,13 @@ exports[`DataTable should render 1`] = `
>
<h4
className="bx--data-table-header__title"
id="data-table-1__table-container__title"
>
DataTable with toolbar
</h4>
<p
className="bx--data-table-header__description"
id="data-table-1__table-container__description"
/>
</div>
<TableToolbar
Expand Down Expand Up @@ -2503,10 +2511,14 @@ exports[`DataTable should render 1`] = `
</section>
</TableToolbar>
<Table
aria-describedby="data-table-1__table-container__description"
aria-labelledby="data-table-1__table-container__title"
isSortable={false}
size="normal"
>
<table
aria-describedby="data-table-1__table-container__description"
aria-labelledby="data-table-1__table-container__title"
className="bx--data-table bx--data-table--no-border"
>
<TableHead>
Expand Down Expand Up @@ -2776,8 +2788,10 @@ exports[`DataTable sticky header should render 1`] = `
Object {
"type": "return",
"value": <TableContainer
descriptionId="data-table-24__table-container__description"
stickyHeader={true}
title="DataTable with toolbar"
titleId="data-table-24__table-container__title"
>
<TableToolbar
aria-label="data table toolbar"
Expand Down Expand Up @@ -2869,6 +2883,8 @@ exports[`DataTable sticky header should render 1`] = `
</TableToolbarContent>
</TableToolbar>
<Table
aria-describedby="data-table-24__table-container__description"
aria-labelledby="data-table-24__table-container__title"
isSortable={false}
size="normal"
stickyHeader={true}
Expand Down Expand Up @@ -2956,8 +2972,10 @@ exports[`DataTable sticky header should render 1`] = `
translateWithId={[Function]}
>
<TableContainer
descriptionId="data-table-24__table-container__description"
stickyHeader={true}
title="DataTable with toolbar"
titleId="data-table-24__table-container__title"
>
<div
className="bx--data-table-container bx--data-table--max-width"
Expand All @@ -2967,11 +2985,13 @@ exports[`DataTable sticky header should render 1`] = `
>
<h4
className="bx--data-table-header__title"
id="data-table-24__table-container__title"
>
DataTable with toolbar
</h4>
<p
className="bx--data-table-header__description"
id="data-table-24__table-container__description"
/>
</div>
<TableToolbar
Expand Down Expand Up @@ -3506,6 +3526,8 @@ exports[`DataTable sticky header should render 1`] = `
</section>
</TableToolbar>
<Table
aria-describedby="data-table-24__table-container__description"
aria-labelledby="data-table-24__table-container__title"
isSortable={false}
size="normal"
stickyHeader={true}
Expand All @@ -3514,6 +3536,8 @@ exports[`DataTable sticky header should render 1`] = `
className="bx--data-table_inner-container"
>
<table
aria-describedby="data-table-24__table-container__description"
aria-labelledby="data-table-24__table-container__title"
className="bx--data-table bx--data-table--no-border bx--data-table--sticky-header"
>
<TableHead>
Expand Down