Skip to content

Commit

Permalink
fix: table header wrapping (#218)
Browse files Browse the repository at this point in the history
* fix: table header wrapping.

* Fix failing test.

* Fix another failing test.

* fix broken table test

* typescript appeasement

Co-authored-by: Juan Fabrega <[email protected]>
  • Loading branch information
Jesse Carmine and juanfabrega authored Sep 4, 2020
1 parent 14f5ee2 commit 320301c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
13 changes: 9 additions & 4 deletions src/components/Table/Table.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,14 @@ describe('Table', () => {
sortedColumn={{ dataKey: 'flavor', sortDirection: 'ascending' }}
/>);

const { getByTestId } = within(screen.getByText('Flavor'));

expect(getByTestId('tableHeaderCellSortAsc-testid')).toBeInTheDocument();
const headingSpan = screen.getByText('Flavor');
expect(headingSpan).toBeInTheDocument();
const headingElement = headingSpan.closest('th');
expect(headingElement).toBeInTheDocument();
if (headingElement) {
const { getByTestId } = within(headingElement);
expect(getByTestId('tableHeaderCellSortAsc-testid')).toBeInTheDocument();
}
});
});

Expand Down Expand Up @@ -216,7 +221,7 @@ describe('Table', () => {
/>,
);

const tableHeaderCell = screen.getByText('Flavor');
const tableHeaderCell = screen.getByText('Flavor').closest('th');
expect(tableHeaderCell).toHaveStyle({ width: '100px', maxWidth: '100px' });
});
});
Expand Down
11 changes: 8 additions & 3 deletions src/components/Table/TableHeaderCell/TableHeaderCell.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
padding: var(--size-spacing-sm);
text-align: left;
text-transform: uppercase;
white-space: nowrap;
color: var(--table-header-color);
font-size: var(--table-header-font-size);
font-weight: 600;
Expand Down Expand Up @@ -32,8 +33,12 @@
&.align-center {
text-align: center;
}
}

.sort-icon {
margin-left: var(--table-header-sort-icon-spacing);
.heading {
white-space: initial;
}

.sort-icon {
margin-left: var(--table-header-sort-icon-spacing);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('TableHeaderCell', () => {
</TableHeaderCell>,
);

const tableHeaderCell = screen.getByText('ID');
const tableHeaderCell = screen.getByText('ID').closest('th');

expect(tableHeaderCell).toHaveStyle({ width: '200px', maxWidth: '200px' });
});
Expand Down
4 changes: 3 additions & 1 deletion src/components/Table/TableHeaderCell/TableHeaderCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ const TableHeaderCell: FC<TableHeaderCellProps> = ({
onClick={handleSort}
onKeyDown={handleKeyPress}
>
{column.heading}
<span className={styles.heading}>
{column.heading}
</span>
{isSortable && renderIcon()}
</th>
);
Expand Down

0 comments on commit 320301c

Please sign in to comment.