Skip to content

Commit

Permalink
Fix DataTable header styling when sortable (#5423)
Browse files Browse the repository at this point in the history
* Fix DataTable header styling

* Fix comment

* Incorporate feedback

* Ensure pad only applied once

* Update styling condition

Co-authored-by: Eric Soderberg <eric.soderberg@hpe.com>
  • Loading branch information
taysea and ericsoderberghp committed Jul 12, 2021
1 parent cde3da8 commit 4b1359f
Show file tree
Hide file tree
Showing 2 changed files with 353 additions and 337 deletions.
12 changes: 10 additions & 2 deletions src/js/components/DataTable/Header.js
Expand Up @@ -50,10 +50,16 @@ const separateThemeProps = (theme) => {

// build up CSS from basic to specific based on the supplied sub-object paths.
// adapted from StyledButtonKind to only include parts relevant for DataTable
const buttonStyle = ({ theme }) => {
const buttonStyle = ({ pad, theme }) => {
const styles = [];
const [layoutProps, , iconProps] = separateThemeProps(theme);

// if cell is sortable, we want pad to be applied
// to the button instead of the cell
if (pad) {
styles.push(kindPartStyles({ pad }, theme));
}

if (layoutProps) {
styles.push(kindPartStyles(layoutProps, theme));
}
Expand Down Expand Up @@ -253,6 +259,7 @@ const Header = forwardRef(
fill="vertical"
onClick={onSort(property)}
sort={sort}
pad={cellProps.pad}
sortable
>
<Box
Expand Down Expand Up @@ -331,7 +338,8 @@ const Header = forwardRef(
background={cellProps.background}
border={cellProps.border}
onWidth={updateWidths}
pad={cellProps.pad}
// if sortable, pad will be included in the button styling
pad={sortable === false || !onSort ? cellProps.pad : 'none'}
pin={cellPin}
plain
pinnedOffset={pinnedOffset && pinnedOffset[property]}
Expand Down

0 comments on commit 4b1359f

Please sign in to comment.