Skip to content

Commit

Permalink
fix(DataTable): useStaticWidth fix for title/description (#9632)
Browse files Browse the repository at this point in the history
* fix(DataTable): ensure header matches content with useStaticWidth

* test(snapshot): update snapshots

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
tw15egan and kodiakhq[bot] authored Sep 20, 2021
1 parent a803128 commit 9bba19b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,10 @@
width: auto;
}

.#{$prefix}--data-table-container--static {
width: fit-content;
}

// -------------
// Sticky header
// -------------
Expand Down
6 changes: 6 additions & 0 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,9 @@ Map {
"title": Object {
"type": "node",
},
"useStaticWidth": Object {
"type": "bool",
},
},
},
"TableExpandHeader": Object {
Expand Down Expand Up @@ -1769,6 +1772,9 @@ Map {
"title": Object {
"type": "node",
},
"useStaticWidth": Object {
"type": "bool",
},
},
},
"TableExpandHeader" => Object {
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/components/DataTable/DataTable-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const props = () => ({
'lg'
),
stickyHeader: boolean('Sticky header (experimental)', false),
useStaticWidth: boolean('Use static width (useStaticWidth)', false),
});

export default {
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/components/DataTable/DataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,11 @@ export default class DataTable extends React.Component {
* Helper utility to get the TableContainer Props.
*/
getTableContainerProps = () => {
const { stickyHeader } = this.props;
const { stickyHeader, useStaticWidth } = this.props;

return {
stickyHeader,
useStaticWidth,
};
};

Expand Down
7 changes: 7 additions & 0 deletions packages/react/src/components/DataTable/TableContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ const TableContainer = ({
title,
description,
stickyHeader,
useStaticWidth,
...rest
}) => {
const tableContainerClasses = cx(
className,
`${prefix}--data-table-container`,
{
[`${prefix}--data-table--max-width`]: stickyHeader,
[`${prefix}--data-table-container--static`]: useStaticWidth,
}
);

Expand Down Expand Up @@ -60,6 +62,11 @@ TableContainer.propTypes = {
* Provide a title for the Table
*/
title: PropTypes.node,

/**
* If true, will use a width of 'fit-content' to match the inner table width
*/
useStaticWidth: PropTypes.bool,
};

export default TableContainer;

0 comments on commit 9bba19b

Please sign in to comment.